Derivatives

A Derivative is a financial instrument whose value is derived from the performance of an underlying asset, index, or other financial entity. We model them via some payoff function that takes the underlying asset's price and returns the derivative's value.

Types

Orcus.InstrumentKeyType
InstrumentKey(ticker::String, kind::Symbol, strike::Union{Float64,Nothing}, expiry::Union{Int,Nothing})

Hashable identifier under which positions net. Two fills net into the same position iff their keys are equal: same ticker, same derivative type, same strike (options) and same expiry (short options). Buy and Sell on one ticker are distinct keys and do not net against each other.

InstrumentKey("AAPL", :Buy, nothing, nothing)
# output

InstrumentKey("AAPL", :Buy, nothing, nothing)
source
Orcus.@generate_derivativeMacro
@generate_derivative(Name::Symbol, structure::Expr, price_func::Expr)

Macro to generate a new derivative type. Takes a name, a structure function (for the payoff), and a price function.

Examples

@generate_derivative NewBuy x->x (val,premium)->val+premium

x = asset()
name(NewBuy(x,10))

# output

"NewBuy"
source
Orcus.BuyType
Buy(underlying::Asset, premium::Number=0)

A long position in the underlying asset itself.

Random.seed!(1);
A=asset();
Buy(A,10).price
# output

19.45573478603903
source
Orcus.SellType
Sell(underlying::Asset, premium::Number=0)

A short position in the underlying asset itself.

Random.seed!(1);
A=asset();
Sell(A,10).price
# output

0.5442652139609674
source
Orcus.LongCallType
LongCall(underlying::Asset, strike::Number, premium::Number=0)

A long call option on the underlying asset.

Random.seed!(1);
A=asset();
payoff(LongCall(A,100.0,5), 110.0)
# output

10.0
source
Orcus.LongPutType
LongPut(underlying::Asset, strike::Number, premium::Number=0)

A long put option on the underlying asset.

Random.seed!(1);
A=asset();
payoff(LongPut(A,100.0,5), 90.0)
# output

10.0
source
Orcus.ShortCallType
ShortCall(underlying::Asset, strike::Number, premium::Number=0, expiry_days::Int=30)

A short (written) call option on the underlying asset.

Random.seed!(1);
A=asset();
payoff(ShortCall(A,100.0,5), 110.0)
# output

-10.0
source
Orcus.ShortPutType
ShortPut(underlying::Asset, strike::Number, premium::Number=0, expiry_days::Int=30)

A short (written) put option on the underlying asset.

Random.seed!(1);
A=asset();
payoff(ShortPut(A,100.0,5), 90.0)
# output

-10.0
source

Methods

Orcus.nameFunction
name(D::Derivative)

The derivative's type name.

Random.seed!(1);
A=asset();
name(Buy(A,10))
# output

"Buy"
source
Orcus.u_valueFunction
u_value(D::Derivative)

Current value of the derivative's underlying asset.

Random.seed!(1);
A=asset();
u_value(Buy(A,10))
# output

9.455734786039033
source
u_value(P::Position)

Current value of the position in the underlying's own price units, before fx conversion.

Random.seed!(1);
A=asset();
P=Position(Buy(A,0));
Orcus.apply_trade!(P, 10.0, value(A), 0.0);
u_value(P)
# output

94.55734786039032
source
Orcus.payoffFunction
payoff(D::Derivative, x)

The derivative's payoff evaluated at underlying value x.

Random.seed!(1);
A=asset();
payoff(Buy(A,10), 5.0)
# output

5.0
source
Orcus.valueMethod
value(D::Derivative)

Current mark-to-market value of the derivative.

Random.seed!(1);
A=asset();
value(Buy(A,10))
# output

9.455734786039033
source
Orcus.abs_returnMethod
abs_return(D::Derivative)

Unrealized P&L: current value minus entry price.

Random.seed!(1);
A=asset();
abs_return(Buy(A,10))
# output

-9.999999999999998
source
Orcus.pct_returnMethod
pct_return(D::Derivative)

Unrealized P&L as a fraction of the entry price.

Random.seed!(1);
A=asset();
pct_return(Buy(A,10))
# output

-0.5139872695620706
source
Orcus.log_returnMethod
log_return(D::Derivative)

Log return of current value over entry price (-Inf if the value is non-positive).

Random.seed!(1);
A=asset();
log_return(Buy(A,10))
# output

-0.7215204611079813
source
Orcus.priceFunction
price(D::Derivative)

The derivative's entry price, can be negative.

Random.seed!(1);
A=asset();
price(Buy(A,10))
# output

19.45573478603903
source
price(order::Order)

The price of a placed order, can be negative.

Random.seed!(1234);
A=asset();
B=Buy(A,10);
O=order(B,10);
price(O)
# output

788.771178523604
source
price(T::Trade)

Cost basis of the trade's volume at its derivative's entry price.

Random.seed!(1234);
A = asset();
B = Buy(A, 10);
O = order(B, 100);
T = Trade(O);
price(T)
# output

7887.71178523604
source
price(P::Position)

Cost basis of the position (net_qty * avg_cost).

Random.seed!(1);
A=asset();
P=Position(Buy(A,0));
Orcus.apply_trade!(P, 10.0, value(A), 0.0);
price(P)
# output

94.55734786039032
source
Orcus.instrument_keyFunction
instrument_key(D::Derivative)

The InstrumentKey a given derivative's fills net under.

Random.seed!(1);
A=asset();
instrument_key(Buy(A,10))
# output

InstrumentKey("BJSQ", :Buy, nothing, nothing)
source
Orcus.print_propsMethod
print_props(D::Derivative)

Print all the current properties of the input derivative.

Examples

Random.seed!(456);
A = asset();
B = Buy(A,10);
Orcus.print_props(B)
# output

========================================
Assets: KPGR
Derivative type: Derivative of Type 'Buy' on KPGR
Underlying value: 47.33678213108721
Derivative value: 47.33678213108721
Price paid: 57.33678213108721
Strike price: None
Absolute return: -10.0
Percentage return: -0.174408113401574
Log return: -0.1916547115821651
========================================
source