[英]Do we have any functions in python that can calculate Z-score for the given p value?
[英]How do you calculate a trader's P&L given their trade history?
給定一系列交易
Symbol,Quantity,Price,Side
SPY,100,127,Buy
SPY,87,125,Sell
SPY,109,115,Sell
SPY,122,95,Sell
SPY,66,89,Buy
SPY,101,175,Sell
您如何以編程方式計算該交易者隨時間變化的表現百分比? 有圖書館可以為您做到這一點嗎?
想法是使用這些數據隨時間創建%P&L圖表,以了解該交易員的表現並將其與其他交易員進行比較。
variables used:
- pos_base = 0 // base price of the position, at any given time
- pos_amount = 0 // position amount (negative for shorts), at any given time
- pl = 0 // total P/L, at any given time, fees already removed
- tot_fees = 0 // total fees paid
- volume = 0 // total volume exchanged
RECORD_EXECUTION(side, amount, price, fee_rate)
{
// normalize amount
n_amount = amount * (side == buy ? 1.0 : -1.0)
// remember base price and amount before changing them
prev_base = pos_base
prev_amount = pos_amount
// update 'virtual' position
pos_amount += n_amount
pos_base = pos_amount == 0.0 ? 0.0 : (prev_amount * prev_base + n_amount * price) / pos_amount
if ((prev_amount < 0.0 && pos_amount > 0.0) || (prev_amount > 0.0 && pos_amount < 0.0)) pos_base = price
// calculate fees paid
fees_paid = amount * price * fee_rate
tot_fees += fees_paid
// update P/L
if (prev_amount < 0.0 && pos_amount >= 0.0) pl += (prev_base - price) * -prev_amount // short closed
if (prev_amount > 0.0 && pos_amount <= 0.0) pl += (price - prev_base) * prev_amount // long closed
pl -= fees_paid
// keep track of total volume
volume += amount
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.