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.Derivative — Type
DerivativeAbstract type for all derivatives.
Orcus.InstrumentKey — Type
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)Orcus.@generate_derivative — Macro
@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"Orcus.Sell — Type
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.5442652139609674Orcus.LongCall — Type
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.0Orcus.LongPut — Type
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.0Orcus.ShortCall — Type
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.0Orcus.ShortPut — Type
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.0Methods
Orcus.name — Function
name(D::Derivative)The derivative's type name.
Random.seed!(1);
A=asset();
name(Buy(A,10))
# output
"Buy"Orcus.u_value — Function
u_value(D::Derivative)Current value of the derivative's underlying asset.
Random.seed!(1);
A=asset();
u_value(Buy(A,10))
# output
9.455734786039033u_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.55734786039032Orcus.payoff — Function
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.0Orcus.value — Method
value(D::Derivative)Current mark-to-market value of the derivative.
Random.seed!(1);
A=asset();
value(Buy(A,10))
# output
9.455734786039033Orcus.abs_return — Method
abs_return(D::Derivative)Unrealized P&L: current value minus entry price.
Random.seed!(1);
A=asset();
abs_return(Buy(A,10))
# output
-9.999999999999998Orcus.pct_return — Method
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.5139872695620706Orcus.log_return — Method
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.7215204611079813Orcus.price — Function
price(D::Derivative)The derivative's entry price, can be negative.
Random.seed!(1);
A=asset();
price(Buy(A,10))
# output
19.45573478603903price(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.771178523604price(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.71178523604price(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.55734786039032Orcus.instrument_key — Function
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)Orcus.print_props — Method
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
========================================