Thursday, March 2, 2023

Realized profit in crpto (Improving Accuracy in Transaction Value Calculation)

In my previous post, I discussed how calculating the value of a transaction from different prices can be inaccurate. After much thought, I decided to switch to calculating from transactions as the only way to ensure accuracy.

To do this, I used Python to write a program that would perform the calculations. However, I encountered some challenges due to certain methods not making sense.

Firstly, I had to determine whether the transaction was a buy or a sell. If it was a sell, then I had to check all the previous buy transactions to determine the correct value. The priority was given to the buy price that was closest to the sell price (and positive when close). However, this approach had a bug problem and was not ideal. For instance, if I bought at prices 10, 12, 13, and 14 and sold at 14.1, my ideal system would sell from buy price 13. However, my program would sell at buy price 14 (including fees) as it was still positive.

To fix this issue, I tried adding an x value to fix the buy and sell variant. For example, if x = 1, my program would sell at buy price 13. Although this seemed to work, my program still had some bugs related to this.

In conclusion, I will continue to work on fixing these bugs to ensure the accuracy of my program. By calculating from transactions, I believe that it is possible to obtain more accurate results than by calculating from different prices.

 

 

 

 Link for my calculator : https://github.com/AdeptEinzbern/Realized-profit-in-trading

Saturday, February 4, 2023

Realized profit calculation

This is, equation to find out how much money you made in  trading. useful with re-balance and grid
If you trade forex before and you jump to crypto, you gonna miss the realized profit.
the first I know if I wanna get my profit I must do a transaction history on my own,
for example, I bought at 10 and sell at 15, I got 5 as my realized profit, it work perfectly fine,
but I start have a problem when I have so many portfolio to handle.
So I need figure out this equation to help me solve the problem,
The concept is easy, it have two scenario if price higher than the start or the price lower than the start,
First we need to note our start assets and price when initial,


First price lower than the start.

Because grid or re-balance had significant to sell all the way before we hit the start price, and current price is lower how much many we actually had?

 The first we need to know what exposure we need to adjust at that price

for example I need to hold 1.9798 LTC when price at 99.500 LTC/USD

no matter how much I hold before I need to adjust to 1.9798 LTC,

and when to price starting go up to our started price (for example start price is 100 LTC/USD)

it gonna be like this.

Price           LTC hold
99.5000      1.9698
99.7500      1.9599
100.0000    1.9500

 So we need to sell all the way to  started price (100 LTC/USD)

Put all these factor to equation it gonna be like this 

(1.9798 come from exposure at price 99.2500 LTC/USD)

y =   (1.9798 - 1.9698) + (1.9698 - 1.9599) + (1.9599 - 1.9500)

y =  0.01 +  0.0099 + 0.0099

y = 0.0298


z = (0.01 * 99.5) + (0.0099 * 99.75) + (0.0099 * 100.00)

z = 0.995 + 0.987525 + 0.99

z = 2.9725


x = 2.9725 - 0.0298(99.500)

x = 0.0074


So our realized profit all time  of our portfolio at price 99.50 is 0.0074.


Second price higher than the start (it's gonna be easy )

x = ((current ltc hold)start price) + usd available - started asset

x = (1.9698)100.00 + 

x = 196.98 + your usd left - started asset


The second is so easy not like the first one because the first if price go lower we need to sell all the way, but if price higher than our start we can just calculate what is more than our started asset if we hold x(ltc) at start price + other assets .


The Trade Plan

การสร้างระบบควบคุมพฤติกรรมการเทรด (Trading Plan) ปัญหาสำคัญของ Trader จำนวนมากไม่ใช่การขาดความรู้ แต่คือการไม่มีเเผนที่กำหนดกฏการเทรดไว้อย่า...