packages feed

trade-journal 0.0.1 → 0.0.2

raw patch · 2 files changed

+189/−26 lines, 2 files

Files

test/ModelTests.hs view
@@ -121,6 +121,7 @@ simpleBuy :: Property simpleBuy = property $ do   b <- forAll $ genTimed genLot+  let c = (b ^. item . amount) * (b ^. item . price)   -- A simple buy   lift $     processActionsWithChanges@@ -130,12 +131,20 @@             AddEvent (Opened True <$> b),             Result (Buy <$> (b & item . details <>~ [Position Open]))           ],-          [Buy <$> (b & item . details <>~ [Position Open])]+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  )+          ]         )  buyBuy :: Property buyBuy = property $ do   b <- forAll $ genTimed genLot+  let c = (b ^. item . amount) * (b ^. item . price)   lift $     processActionsWithChanges       [ Buy <$> b,@@ -149,14 +158,27 @@             AddEvent (Opened True <$> b),             Result (Buy <$> (b & item . details <>~ [Position Open]))           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),-            Buy <$> (b & item . details <>~ [Position Open])+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),+            Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (2 * (c ^. coerced . to negate)),+                            Net (c ^. coerced . to negate)+                          ]+                  )           ]         )  buySellBreakeven :: Property buySellBreakeven = property $ do   b <- forAll $ genTimed genLot+  let c = (b ^. item . amount) * (b ^. item . price)   -- A buy and sell at break-even   lift $     processActionsWithChanges@@ -174,8 +196,21 @@               ),             RemoveEvent 1           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),-            Sell <$> (b & item . details <>~ [Position Close, Gain 0])+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),+            Sell+              <$> ( b & item . details+                      <>~ [ Position Close,+                            Gain 0,+                            Balance 0,+                            Net (c ^. coerced)+                          ]+                  )           ]         ) @@ -184,6 +219,8 @@   b <- forAll $ genTimed genLot   let s = b       sp = s & item . price +~ 10+      c = (b ^. item . amount) * (b ^. item . price)+      sc = (sp ^. item . amount) * (sp ^. item . price)   -- A buy and sell at a profit   lift $     processActionsWithChanges@@ -201,8 +238,21 @@               ),             RemoveEvent 1           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),-            Sell <$> (sp & item . details <>~ [Position Close, Gain 10])+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),+            Sell+              <$> ( sp & item . details+                      <>~ [ Position Close,+                            Gain 10,+                            Balance (c ^. coerced . to negate + sc ^. coerced),+                            Net (sc ^. coerced)+                          ]+                  )           ]         ) @@ -212,6 +262,8 @@   let b2 = b & item . amount *~ 2       s = b       sp = s & item . price +~ 10+      c2 = (b2 ^. item . amount) * (b2 ^. item . price)+      sc = (sp ^. item . amount) * (sp ^. item . price)   -- A buy and sell at a partial profit   lift $     processActionsWithChanges@@ -229,8 +281,21 @@               ),             ReplaceEvent 1 (Opened True <$> b)           ],-          [ Buy <$> (b2 & item . details <>~ [Position Open]),-            Sell <$> (sp & item . details <>~ [Position Close, Gain 10])+          [ Buy+              <$> ( b2 & item . details+                      <>~ [ Position Open,+                            Balance (c2 ^. coerced . to negate),+                            Net (c2 ^. coerced . to negate)+                          ]+                  ),+            Sell+              <$> ( sp & item . details+                      <>~ [ Position Close,+                            Gain 10,+                            Balance (c2 ^. coerced . to negate + sc ^. coerced),+                            Net (sc ^. coerced)+                          ]+                  )           ]         ) @@ -238,8 +303,9 @@ buySellLoss = property $ do   b <- forAll $ genTimed genLot   let s = b-      sl =-        s & item . price -~ 1+      sl = s & item . price -~ 1+      c = (b ^. item . amount) * (b ^. item . price)+      sc = (sl ^. item . amount) * (sl ^. item . price)   -- A buy and sell at a loss   lift $     processActionsWithChanges@@ -261,8 +327,24 @@             Submit (sl & item . price .~ 1),             SubmitEnd           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),-            Sell <$> (sl & item . details <>~ [Position Close, Loss 1])+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),+            Sell+              <$> ( sl & item . details+                      <>~ [ Position Close,+                            Loss 1,+                            Balance+                              ( c ^. coerced . to negate+                                  + sc ^. coerced+                              ),+                            Net (sc ^. coerced)+                          ]+                  )           ]         ) @@ -275,6 +357,9 @@           & item . details <>~ [WashTo "A" Nothing]       b2 =         b & item . details <>~ [WashApply "A" (b ^. item . amount)]+      c = (b ^. item . amount) * (b ^. item . price)+      c2 = (b2 ^. item . amount) * (b2 ^. item . price)+      sc = (sl ^. item . amount) * (sl ^. item . price)   -- A buy and sell at a loss, followed by a buy   lift $     processActionsWithChanges@@ -314,18 +399,44 @@                       )               )           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),             Sell               <$> ( sl & item . details                       <>~ [ Position Close,-                            Loss 1+                            Loss 1,+                            Balance+                              ( c ^. coerced . to negate+                                  + sc ^. coerced+                              ),+                            Net (sc ^. coerced)                           ]                   ),-            Wash <$> (sl & item . price .~ 1),+            Wash+              <$> ( sl & item . price .~ 1+                      & item . details+                        <>~ [ Balance+                                ( c ^. coerced . to negate+                                    + sc ^. coerced+                                ),+                              Net 0+                            ]+                  ),             Buy               <$> ( b2 & item . details                       <>~ [ Position Open,-                            Washed 1+                            Washed 1,+                            Balance+                              ( c ^. coerced . to negate+                                  + sc ^. coerced+                                  + c2 ^. coerced . to negate+                              ),+                            Net (c2 ^. coerced . to negate)                           ]                   )           ]@@ -336,6 +447,8 @@   b <- forAll $ genTimed genLot   let s = b       sl = s & item . price -~ 1+      c = (b ^. item . amount) * (b ^. item . price)+      sc = (sl ^. item . amount) * (sl ^. item . price)   -- A buy, a buy and then a sell at a loss   lift $     processActionsWithChanges@@ -374,13 +487,41 @@               ),             SubmitEnd           ],-          [ Buy <$> (b & item . details <>~ [Position Open]),-            Buy <$> (b & item . details <>~ [Position Open]),+          [ Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate),+                            Net (c ^. coerced . to negate)+                          ]+                  ),+            Buy+              <$> ( b & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced . to negate * 2),+                            Net (c ^. coerced . to negate)+                          ]+                  ),             Sell-              <$> (sl & item . details <>~ [Position Close, Loss 1]),+              <$> ( sl & item . details+                      <>~ [ Position Close,+                            Loss 1,+                            Balance+                              ( c ^. coerced . to negate * 2+                                  + sc ^. coerced+                              ),+                            Net (sc ^. coerced)+                          ]+                  ),             Wash               <$> ( b & item . price .~ 1-                      & item . details <>~ [Washed (b ^. item . price)]+                      & item . details+                        <>~ [ Washed (b ^. item . price),+                              Balance+                                ( c ^. coerced . to negate * 2+                                    + sc ^. coerced+                                ),+                              Net 0+                            ]                   )           ]         )@@ -388,6 +529,7 @@ simpleSell :: Property simpleSell = property $ do   s <- forAll $ genTimed genLot+  let c = (s ^. item . amount) * (s ^. item . price)   -- A simple sell   lift $     processActionsWithChanges@@ -397,13 +539,21 @@             AddEvent (Opened False <$> s),             Result (Sell <$> (s & item . details <>~ [Position Open]))           ],-          [Sell <$> (s & item . details <>~ [Position Open])]+          [ Sell+              <$> ( s & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced),+                            Net (c ^. coerced)+                          ]+                  )+          ]         )  sellBuyProfit :: Property sellBuyProfit = property $ do   b <- forAll $ genTimed genLot   let s = b+      c = (s ^. item . amount) * (s ^. item . price)   -- A sell and buy at a profit   lift $     processActionsWithChanges@@ -421,7 +571,20 @@               ),             RemoveEvent 1           ],-          [ Sell <$> (s & item . details <>~ [Position Open]),-            Buy <$> (b & item . details <>~ [Position Close, Gain 0])+          [ Sell+              <$> ( s & item . details+                      <>~ [ Position Open,+                            Balance (c ^. coerced),+                            Net (c ^. coerced)+                          ]+                  ),+            Buy+              <$> ( b & item . details+                      <>~ [ Position Close,+                            Gain 0,+                            Balance 0,+                            Net (c ^. coerced . to negate)+                          ]+                  )           ]         )
trade-journal.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: bcab8d5bdeae3d554c45f80204fd191d5ad66fc5bcca8615b115e202dd2787cd+-- hash: 57139492680a59de2779610c2e2a97994abdbf405b12b6482afe8dcc8264cfa2  name:           trade-journal-version:        0.0.1+version:        0.0.2 description:    Command-line reporting utility for processing trade journals. author:         John Wiegley maintainer:     johnw@newartisans.com