Upload e.g. calculating lotsize and margin with leverage using approximation.py
Browse files
e.g. calculating lotsize and margin with leverage using approximation.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pxyq # main function call is `pxyq.column('ASSET')`
|
| 2 |
+
|
| 3 |
+
ASSET = 'AUDCADc'
|
| 4 |
+
digits = pxyq.true_decimal_digits(ASSET) # AUDCADc has 5 decimal digits
|
| 5 |
+
|
| 6 |
+
sl_distance = 0.00841
|
| 7 |
+
betsize = 231 # cash
|
| 8 |
+
# lotsize = "missing"
|
| 9 |
+
lotsize_decimal_digits = 2
|
| 10 |
+
cash_decimal_digits = 2
|
| 11 |
+
# ml_50 = "missing" # margin with leverage 50
|
| 12 |
+
# ml_100 = "missing" # margin with leverage 100
|
| 13 |
+
# ml_200 = "missing" # margin with leverage 200
|
| 14 |
+
# ml_300 = "missing" # margin with leverage 1000
|
| 15 |
+
|
| 16 |
+
# use float because the cells we are calling is best suited for floats
|
| 17 |
+
proxy_sl_distance = float(pxyq.proxy_stoploss_distance_covering_1_cash(ASSET))
|
| 18 |
+
proxy_betsize = 1 # proxies is always cover or equivalent to 1 cash
|
| 19 |
+
proxy_lotsize = float(pxyq.proxy_lotsize_covering_1_cash(ASSET))
|
| 20 |
+
|
| 21 |
+
proxy_ml_50 = float(pxyq.proxy_margin_with_leverage_50_covering_1_cash(ASSET))
|
| 22 |
+
proxy_ml_100 = float(pxyq.proxy_margin_with_leverage_100_covering_1_cash(ASSET))
|
| 23 |
+
proxy_ml_200 = float(pxyq.proxy_margin_with_leverage_200_covering_1_cash(ASSET))
|
| 24 |
+
proxy_ml_1000 = float(pxyq.proxy_margin_with_leverage_1000_covering_1_cash(ASSET))
|
| 25 |
+
|
| 26 |
+
# calculate for lotsize and margins with leverages
|
| 27 |
+
# lotsize
|
| 28 |
+
lotsize = ((proxy_sl_distance / proxy_betsize) * proxy_lotsize) / (sl_distance / betsize)
|
| 29 |
+
# margin with leverage
|
| 30 |
+
ml_50 = (proxy_ml_50 * lotsize) / proxy_lotsize
|
| 31 |
+
ml_100 = (proxy_ml_100 * lotsize) / proxy_lotsize
|
| 32 |
+
ml_200 = (proxy_ml_200 * lotsize) / proxy_lotsize
|
| 33 |
+
ml_1000 = (proxy_ml_1000 * lotsize) / proxy_lotsize
|
| 34 |
+
|
| 35 |
+
# cli output
|
| 36 |
+
print(f"Lotsize for {ASSET}: {lotsize:.{lotsize_decimal_digits}f} lot, which is equivalent to a betsize of {betsize:.{cash_decimal_digits}f} cash")
|
| 37 |
+
print(f"The margin with leverage 1:50 for {ASSET} lotsize of {lotsize:.{lotsize_decimal_digits}f} is {ml_50:.{cash_decimal_digits}f} cash")
|
| 38 |
+
print(f"The margin with leverage 1:100 for {ASSET} lotsize of {lotsize:.{lotsize_decimal_digits}f} is {ml_100:.{cash_decimal_digits}f} cash")
|
| 39 |
+
print(f"The margin with leverage 1:200 for {ASSET} lotsize of {lotsize:.{lotsize_decimal_digits}f} is {ml_200:.{cash_decimal_digits}f} cash")
|
| 40 |
+
print(f"The margin with leverage 1:1000 for {ASSET} lotsize of {lotsize:.{lotsize_decimal_digits}f} is {ml_1000:.{cash_decimal_digits}f} cash")
|
| 41 |
+
print(f"Which all covers the stoploss distance of {ASSET}: {sl_distance:.{digits}f}")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
"""
|
| 45 |
+
# cli output sample
|
| 46 |
+
Lotsize for AUDCADc: 0.39 lot, which is equivalent to a betsize of 231.00 cash
|
| 47 |
+
The margin with leverage 1:50 for AUDCADc lotsize of 0.39 is 767.98 cash
|
| 48 |
+
The margin with leverage 1:100 for AUDCADc lotsize of 0.39 is 383.99 cash
|
| 49 |
+
The margin with leverage 1:200 for AUDCADc lotsize of 0.39 is 192.09 cash
|
| 50 |
+
The margin with leverage 1:1000 for AUDCADc lotsize of 0.39 is 38.42 cash
|
| 51 |
+
Which all covers the stoploss distance of AUDCADc: 0.00841
|
| 52 |
+
|
| 53 |
+
"""
|