Profit / loss trading calculator for share market historical data

AI Thread Summary
A share market trading calculator is being developed to calculate profit and loss from historical data using moving averages, without leveraging. The initial setup includes a bank and equity of $10,000 each, with formulas established for buying and selling shares. The current implementation works for a single transaction but struggles with multiple buys and sells, and the handling of equity. It is suggested that a dataframe is necessary to track stock names, values, and share quantities owned. The key principle is that the total value of bank and equity must remain constant before and after transactions.
mp3streetpart
Messages
3
Reaction score
0

Homework Statement



Share market trading calculator.
I have tried to write code to calculate the buy and sell with profit/loss on historical data using moving averages. I'm am not interested in leverage yet.

bank = 10000
equity = 10000
sell = is current price of an instrument on the stock market either in the buy or sell routine.

Homework Equations


The difference in Buy price to sell price times volume.

The Attempt at a Solution


Buy formula
bank = bank - (10000 * sell) Remove money from bank to buy
profit = profit - (10000 * sell) Value to take to sell formula for profit/loss

Sell formula
profit = equity + ((10000 * sell ) + profit) Find profit/loss and compare against Buy
bank = profit: profit = 0


It works for a single buy and sell but I can't work out how to add more buys and sells to the bank or what to do with equity.
 
Physics news on Phys.org
It's a little vague, but it looks like Equity should equal the current value of the stock that you own, at a particular time. You'd need to have a dataframe or some way of holding the stock names and values and how many shares you own of each. Then I guess you have a way to pull the share price for any given historical date?

When you sell shares, then equity is reduced, and bank increases.

At any particular time the value of (Bank + Equity) before a transaction should equal to (Bank + Equity) after transaction.
 
I picked up this problem from the Schaum's series book titled "College Mathematics" by Ayres/Schmidt. It is a solved problem in the book. But what surprised me was that the solution to this problem was given in one line without any explanation. I could, therefore, not understand how the given one-line solution was reached. The one-line solution in the book says: The equation is ##x \cos{\omega} +y \sin{\omega} - 5 = 0##, ##\omega## being the parameter. From my side, the only thing I could...

Similar threads

Back
Top