New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing data for trade details #16
Comments
There was a reason I removed it in this new version..... I just can't remember 100% why at the moment. I think it was related to the leg market price being correct but if the leg had been rolled previously then the leg cost basis was wrong. I will check into this again and put it back if it works without causing confusion for the user. |
I am taking another look at this issue and will add back the leg cost, market value, difference, and percentage. Much like the older IB-Tracker functionality. Once I implement the changes then we should discuss it again to be sure that it meets our needs. I am hoping to have this change done today. |
For the option legs:
|
Looks like the current market value of your Put legs would cost you $2851.02 each to close (total $5702.04). Your current income received on the trade is $3721.30, so it appears you are not currently profitable for this trade(?) |
Last close is 7.00$ |
Ah, okay, I see what the problem is now. Both option legs are exactly the same. The data retrieved from TWS is getting the full 4 positions whereas in TradeTracker you have them split into two different transactions and when I loop the grid, I (incorrectly) display the TWS 4 contract value for both of your legs. I need to fix it so that duplicate option legs are combined into one. |
Please use the values entered in the transaction as the starting point. Please do not divide the value of the TWS by the number of legs. |
I will combine both of the legs so that it shows in the grid as -4 Feb 16 42d 65 P. That way it will match what shows in TWS and also match the value that TWS sends to TradeTracker. |
No, please don't do that. Because you can look at both positions separately. Each has its own PnL. |
Take the value from the transaction for the first column. In my opinion, it is not necessary to take the value from the TWS. |
Maybe I am not understanding correctly. Maybe more talk about this may help. The first column is calculated from incoming TWS data: Instead of using that data, I could use the two values that show in the Trade History for your legs (the values that you had manually entered: 1920.70 and 1800.60). I like that idea. It is the second column that I was mostly referring to previously. That amount is not calculated by me, and is simply the amount that comes in from TWS. The problem is that the amount is the total of all 4 of your Puts and not just 2. To be correct, I would have to take the 2851.02, divide it by 2, and display 1425.51 for each leg in column 2. Does that sound right? |
For column one: For the second column: |
Added new code to calculate the cost basis of individual Option legs. Needs to be tested on new data because the calculation can not be applied to transactions created before this patch. I will see how well this code works this week in a live setting when connected to TWS. Actually, older existing Trades may display correct data UNLESS they contain rolled transactions. In that case, the calculation will be incorrect. |
The value for column 1 is now correct. Great so far. |
Yes, I see the problem and I have a solution for it. I just started working on the fix but I only have it about 50% finished. I will finish it today and post again here when the code is done. Thanks! |
I uploaded new code for the live data grid. I changed where some column data is displayed as well as use better data for the individual line calculations. I have not tested it a 100% yet but hopefully I will have time today to test. |
The width of the fourth column could be slightly larger. Maybe an automatic adjustment of the width across all values of the column makes sense, in combination with a minimum width. |
If the brackets only show that the position is in loss, then I would prefer a "-" in front of the value. I think the red color is right. |
Thanks, I will look at this tomorrow. There is code that should automatically resize the columns contents based on min/max widths. I will check to ensure that code is being applied to that fourth column. I should be able to change from "( )" to negative signs. I haven't had much time to day to test or code anything so hopefully tonight and tomorrow I can get things correct. |
Here is what it looks like with the minus sign and space before the %. Here is what it looks like with ZERO decimal places instead of TWO. Do you have a preference??? (I just committed the source using MINUS sign, SPACE before %, and ZERO decimal places if you I have a few other areas in the program that use parenthesis instead of minus. I should just change everything to minus, right? |
My favorite would be the second one, without the decimal points and with the space. It looks cleaner. Your TradeTracker is getting better every day! |
I think that I like that version also. 😀
Thanks! I am very happy with all of the suggestions you've provided to make this program better. It has come a long way in just a week or so. 👍 |
You should have asked for my help earlier. 😆 |
I have to go out for an hour! Damn. |
Lol. You seem to be there with heart and soul. |
I don't know why IBKR is not correcting the TMF1 -20 PUT 2024-01-19 $6 ---> TMF -2 PUT 2024-01-29 $60 when it sends you the data. Likewise the -40 TMF1 and -2 TMF 2024-02-16 $60 are not being combined. Granted, they are separate symbols in IBKR's eyes (TMF1 and TMF). I wish I could explain why IBKR handles the data the way that they do for this scenario. I wonder if you enter the Trades as follows would they then receive the TWS data: TMF1 -40 PUT 2024-02-16 @ $6 TMF -2 PUT 2024-02-16 @ $60 I have done some online searches to see if this kind of situation has been explained but I have not found anything relevant. |
Could it be that you only subscribe to the tickers that are in the IB portfolio and not those from TradeTracker? |
TradeTracker can get the Ticker data for whatever symbol that you set up for in the Trade. However, TradeTracker will only get the portfolio/leg/option data for positions that you actually own in IB. This is because your entire Portfolio in IB sent to TradeTracker when the program starts and TradeTracker matches the incoming ContractID's from the TWS data to Trades that you have set up manually locally. Once the match has been made then TradeTracker knows which Contract ID's to capture whenever subsequent TWS data related to your open positions arrives. This is part of the matching code logic that TradeTracker uses internally to match IBKR data to your local Trade data:
|
This must be changed. |
I understand what you mean and I am pretty sure that I can query IB for contracts based on stock, option, futures, attributes. I would just have to test to see what streaming data gets received by TradeTracker for all of those different types of underlyings. Actually, since we changed the way we calculate the position cost and display it ActiveTrades grid, the data that we really need on a real time basis from IB would be the current market price. I could then continue to use the Reconcile function to retrieve IB based Portfolio data and compare to local data to ensure that you have not entered local data incorrectly causing a mismatch to what positions you actually own. I guess my only question is: Why would you want to set up a Trade locally within TradeTracker that you do not actually own based on the data in IB???? I am trying to think of a scenario where that would be useful? I am certainly open to changing the way TradeTracker requests information but I would have to do some testing first to make sure that we are not losing any functionality that we currently have. |
I have tried your new approach but (so far) I am unable to retrieve option data for stocks or futures. It could be because the market is closed but I will try again tomorrow during regular trading hours. (I am using the reqMktData api). |
Before you subscribe to the ticker, you could retrieve the last price once. Even if no trading takes place, you will then have the last valid price. I don't know many cases where you can use this. You saw one in my TMF case. You could also create fictitious positions and delete them again so that they don't appear in the report if someone wants to compare two positions. One that he has traded and one that he had as a second choice. Maybe someone has a strategy where they only enter a trade when an option they are watching has fallen 50% to open a real position. |
I'm wondering a few things here. Why are the two values marked in green the same if they are different strike prices? I saw this in your pictures and not just for one trade. The 756.82 marked in red should be negative. Since you get money when you sell the position. If it goes according to the money flow. |
I find the way you use the income and expenditure with the signs very difficult to interpret. It may be that the way you do it is right, but I would always do it from the point of view of my account. |
Good morning, the first column is always the money you have received for the position. The second column is the current market value of the position if you sold it right now. The 3rd and 4th columns are the difference and percentage. It looks like that screenshot you posted is from 3 days ago and there have been fixes to the calculations since then. Here is what that exact same position looks like now: The first column is calculated by assigning the total amount of cash received for the trade ($756.82) among the 3 different legs based on their percentage of contracts. That may not be the best way to do it but I am not sure what the alternative would be? I agree that I should not be playing with the negatives and I will fix that. Here is what the costs of that Trade is showing right now: And here is the market value of the Trade: It has been the calculation and display of the individual leg positions that has caused us problems over the past week. I wonder if it would be an idea to receive the TWS reported costs of the 3 legs, total them, and then use each of their proportions to multiply against the amount received. That might be okay? Using that approach I would not have had to gone the path of tracking individual leg costs from transaction to transaction. I think more thinking and head scratching might be needed here. 😁 |
I'm really sorry if I keep coming back to the point. But actually I expect exactly the same values in the TradeTracker as in the TWS. The profit of 611% is simply misleading. What would be wrong with changing the order management window so that you enter the buy price for each leg instead of a total price? That would be the most accurate. All values can be seen in the TWS after the order has been executed. |
Another total field for price and fee below the input fields. But only as a display. |
I like your ability to photoshop a new screen layout design 👍 |
I don't know what sense a ratio should make at this point. If a leg costs a certain price, then it costs exactly that price and not an adjusted one via a ratio. |
I find this very difficult and complicated. I think the cost basis is 7869 - 3007.96. |
I do also. 😁
I would think that the cost basis would be 3007.96 because that is how much money we received by selling the Puts and subsequent incremental income from rolling. When I am evaluating my position, I want to see how much the position is worth at the current market value, versus how much income I have currently collected. It is the allocation of the costs to the legs that is problematic.
I agree that it is two trades and IB treats them that way (as do all brokers) because when you roll you'll see the realized gain/loss immediately. Of course the problem is that users want to treat all the rolls as part of a single trade. I think I need more thinking.... maybe I will work on something else and let this sit in my subconscious for a while and wait for that "Eureka Moment" to hit me. 😀 |
Okay, I've done more thinking about this. The fundamental problem is getting an accurate starting cost for the legs. Once we have that value then all subsequent transactions involving adding or reducing costing to the legs is easy, and that code is already part of TradeTracker. A few days ago, to calculate that starting point, I included programming logic to simply use the ratio of contracts of the leg to the total contracts of the transaction and multiply that by the income received for the entire transaction. Of course, that is not accurate as some of the long and short legs and put/call skew would value the legs differently. An option would be that when the initial transaction is created, set the legs cost basis to zero, and respond to the first incoming TWS message for that Trade. That message would have the true initial costs of the legs. I would simply test to see that the leg's cost is currently zero and if it is, then assign the incoming TWS cost data. The problem with the above is that it assumes that the user has only entered that first transaction and no other in the same trade. If the user is NOT connected to TWS and enters several transactions for the trade and then later connects to TWS, then I would never get that initial cost data (I would only get the data for most recent transaction). This is the same problem that we are facing right now. I have trades with many transactions and no way to get the initial starting cost. I do not want to go down the path of making the user try to find this cost data for themselves. Maybe there is a IB report that can be run that shows the evolution of the costs but once I force users to have to generate reports just to enter data, then I bet 99% of them will give up and abandon TradeTracker because it will become a hassle. The whole idea of this program from the very beginning was to make things easy. 😁 So, once again, I come back to the ratio approach...... or, should I say, "relative cost base" of the leg. Every time I receive a TWS data message about the Trade, I can calculate the relative costing of the all the legs compared to the overall income received to date for the Trade. Is it perfect? Maybe not. Is it close to what the actual costs would be? Maybe. Another benefit of using this relative cost base approach is that it is easy to implement and willl easily work with existing data and the data of previous TradeTracker (IB-Tracker) databases. Previous users would simply need to start using TradeTracker and everything would work seamlessly under the hood. Anyway, I will continue to do more thinking..... |
I can't quite share your approach of extracting as much data as possible from the TWS and doing "too much" work for the user. As long as everything works, it's ok. But if other numbers appear and the user does not understand transparently where they come from or what is behind them, it becomes difficult. Maybe I'm the wrong person to ask and it would be interesting to hear other opinions. |
I have introduced a GPF when closing a Trade when Live Data connected to TWS. I hope to have this fixed ASAP. |
Okay, should be fixed now. |
Finally, I have have the live Option Leg portfolio data matching the streaming data from TWS. Turned out it was a simple and straight forward implementation. Too bad I wasted so much time on this issue running around in circles. Code is now in the repository and an updated testing EXE posted to https://github.com/PaulSquires/TradeTracker/releases |
When I am connected to the TWS, the individual prices of the single legs are missing as shown on your picture in the readme. Each line has its own P/L, which I would like to see. I am also interested in the current option price. Maybe you can display it in a column.
The text was updated successfully, but these errors were encountered: