Kudos to MMs

Discussion in 'Chit Chat' started by nitro, Oct 23, 2008.

  1. nitro

    nitro

    For those that want to tally the PnL for themselves, here is (really quick and dirty) C# program that computes it. All you have to enter is the entries like this. Say you sold 1300, then exited and went long at 1305, then exited and went flat at 1302. The entry on the command line is:

    -1300, 1305, -1302

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ComputeProfitConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                string entries = Console.ReadLine();
    
                string[] prices = entries.Split(',');
    
                double entry = 0;
                double exit = 0;
    
                double PnL = 0;
                int trade = 0;
                foreach (string priceStr in prices)
                {
                    double tradePrice = double.Parse(priceStr);
                    if (0 == trade)
                    {
                        entry = tradePrice;
                        entry *= -1;
                        trade++;
                    }
                    else
                    {
                        trade+= 2;
    
                        exit = tradePrice;
                        exit *= -1;
    
                        PnL += entry + exit;
                        entry = exit;                   
                    }
                }
    
    
                trade -= 1;
    
                Console.WriteLine("PNL = {0} Number of trades = {1}", PnL, trade);
    
                Console.ReadLine();
            }
        }
    }
    
    
    A good exercise for budding programmers is to modify the above program so as only to have the user enter the sign of the first trade, then the program figures out the rest. This is fine for the crossover system because that is always in the market and is always flipping. This is way less error prone since you only have to input prices like this:

    -1300, 1305, 1302

    and the program figures out whether it was a long or short trade after the first one. It is a good exercise and interesting to turn this program into F#.
     
    #4301     Feb 1, 2012
  2. nitro

    nitro

    SPX, 1326.02. FV, 1144.54. OFV, 1326.44. POFVF, 1318.93.
     
    #4302     Feb 2, 2012
  3. nitro

    nitro

    02/02/2012 09:08:06 OFV = 1326.43800005003 Buy at 1326.02
    02/02/2012 09:08:42 OFV = 1325.77119327726 Sell SPX at 1326.23

    I had a meeting very early this morning. Ran the program under the debugger and left for a meeting. Forgot I had a breakpoint, so when I came back, no simmulations had occurred because the program had stopped on the breakpoint. Hence only two trades so far this morning except the two above when I just restarted the program :( Soon all of this will be very smooth.
     
    #4303     Feb 2, 2012
  4. nitro

    nitro

    02/02/2012 09:34:21 OFV = 1327.61840213299 Buy SPX at 1326.54
    02/02/2012 09:41:05 OFV = 1326.96788658716 Sell SPX at 1327.78
    02/02/2012 09:42:56 OFV = 1328.08198665345 Buy SPX at 1328.08
    02/02/2012 09:43:32 OFV = 1327.29473001006 Sell SPX at 1328.05
     
    #4304     Feb 2, 2012
  5. nitro

    nitro

    02/02/2012 09:45:57 OFV = 1329.7592778409 Buy SPX at 1327.91
     
    #4305     Feb 2, 2012
  6. nitro

    nitro

    SPX, 1327.31. FV, 1153.17. OFV, 1332.93. POFVF, 1325.67.
     
    #4306     Feb 2, 2012
  7. Eat like a bird, s&#t like an elephant. It's coming.
     
    #4307     Feb 2, 2012
  8. nitro

    nitro

    02/02/2012 11:03:57 OFV = 1325.53 Sell SPX at 1325.65
     
    #4308     Feb 2, 2012
  9. nitro

    nitro

    02/02/2012 11:14:40 OFV = 1324.38703473308 Buy at 1323.93
     
    #4309     Feb 2, 2012
  10. nitro

    nitro

    SPX, 1321.6. FV, 1144.49. OFV, 1319.55. POFVF, 1312.37

    02/02/2012 11:23:06 OFV = 1323.36075637333 Sell SPX at 1324.01
     
    #4310     Feb 2, 2012