• Support PF! Buy your school textbooks, materials and every day products Here!

Profit / loss trading calculator for share market historical data

  • #1

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.

Homework Statement





Homework Equations





The Attempt at a Solution

 

Answers and Replies

  • #2
scottdave
Science Advisor
Homework Helper
Insights Author
1,775
738
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.
 

Related Threads on Profit / loss trading calculator for share market historical data

  • Last Post
Replies
3
Views
12K
Replies
4
Views
879
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
8K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
0
Views
2K
Top