[R-SIG-Finance] using quantstrat with custom data

Jon Golenbock jongolenbock at gmail.com
Mon Oct 24 21:34:55 CEST 2016


Thanks Kevin. I actually had just failed to copy-paste the add.signal calls
and figured that out pretty quickly after fixing the previous error.

What I have below is what I've got now (and it runs). probably
unsurprisingly, the data is a 1 minute continous front-month natural gas
contract.

Thank you again.


ts <- structure(list(times = structure(c(1477315440, 1477315500,
1477315560,
1477315620, 1477315680, 1477315740, 1477315800, 1477315860, 1477315920,
1477315980, 1477316040, 1477316100, 1477316160, 1477316220, 1477316280,
1477316340, 1477316400, 1477316460, 1477316520, 1477316580, 1477316640,
1477316700, 1477316760, 1477316820, 1477316880, 1477316940, 1477317000,
1477317060, 1477317120, 1477317180, 1477317240, 1477317300, 1477317360,
1477317420, 1477317480, 1477317540, 1477317600, 1477317660, 1477317720,
1477317780, 1477317840, 1477317900, 1477317960, 1477318020, 1477318080,
1477318140, 1477318200, 1477318260, 1477318320, 1477318380, 1477318440,
1477318500, 1477318560, 1477318620, 1477318680, 1477318740, 1477318800,
1477318860, 1477318920, 1477318980, 1477319040, 1477319100, 1477319160,
1477319220, 1477319280, 1477319340, 1477319400, 1477319460, 1477319520,
1477319580, 1477319640, 1477319700, 1477319760, 1477319820, 1477319880,
1477319940, 1477320000, 1477320060, 1477320120, 1477320180, 1477320240,
1477320300, 1477320360, 1477320420, 1477320480, 1477320540, 1477320600,
1477320660, 1477320720, 1477320780, 1477320840, 1477320900, 1477320960,
1477321020, 1477321080, 1477321140, 1477321200, 1477321260, 1477321320,
1477321380, 1477321440, 1477321500, 1477321560, 1477321620, 1477321680,
1477321740, 1477321800, 1477321860, 1477321920, 1477321980, 1477322040,
1477322100, 1477322160, 1477322220, 1477322280, 1477322340, 1477322400,
1477322460, 1477322520, 1477322580, 1477322640, 1477322700, 1477322760,
1477322820, 1477322880, 1477322940, 1477323000, 1477323060, 1477323120,
1477323180, 1477323240, 1477323300, 1477323360, 1477323420, 1477323480,
1477323540, 1477323600, 1477323660, 1477323720, 1477323780, 1477323840,
1477323900, 1477323960, 1477324020, 1477324080, 1477324140, 1477324200,
1477324260, 1477324320, 1477324380, 1477324440, 1477324500, 1477324560,
1477324620, 1477324680, 1477324740, 1477324800, 1477324860, 1477324920,
1477324980, 1477325040, 1477325100, 1477325160, 1477325220, 1477325280,
1477325340, 1477325400, 1477325460, 1477325520, 1477325580, 1477325640,
1477325700, 1477325760, 1477325820, 1477325880, 1477325940, 1477326000,
1477326060, 1477326120, 1477326180, 1477326240, 1477326300, 1477326360,
1477326420, 1477326480, 1477326540, 1477326600, 1477326660, 1477326720,
1477326780, 1477326840, 1477326900, 1477326960, 1477327020, 1477327080,
1477327140, 1477327200, 1477327260, 1477327320, 1477327380, 1477327440,
1477327500, 1477327560, 1477327620, 1477327680, 1477327740, 1477327800,
1477327860, 1477327920, 1477327980, 1477328040, 1477328100, 1477328160,
1477328220, 1477328280, 1477328340, 1477328400, 1477328460, 1477328520,
1477328580, 1477328640, 1477328700, 1477328760, 1477328820, 1477328880,
1477328940, 1477329000, 1477329060, 1477329120, 1477329180, 1477329240,
1477329300, 1477329360, 1477329420, 1477329480, 1477329540, 1477329600,
1477329660, 1477329720, 1477329780, 1477329840, 1477329900, 1477329960,
1477330020, 1477330080, 1477330140, 1477330200, 1477330260, 1477330320,
1477330380, 1477330440, 1477330500, 1477330560, 1477330620, 1477330680,
1477330740, 1477330800, 1477330860, 1477330920, 1477330980, 1477331040,
1477331100, 1477331160, 1477331220, 1477331280, 1477331340, 1477331400,
1477331460, 1477331520, 1477331580, 1477331640, 1477331700, 1477331760,
1477331820, 1477331880, 1477331940, 1477332000, 1477332060, 1477332120,
1477332180, 1477332240, 1477332300, 1477332360, 1477332420, 1477332480,
1477332540, 1477332600, 1477332660, 1477332720, 1477332780, 1477332840,
1477332900, 1477332960, 1477333020, 1477333080, 1477333140, 1477333200,
1477333260, 1477333320, 1477333380, 1477333440, 1477333500, 1477333560,
1477333620, 1477333680, 1477333740, 1477333800, 1477333860, 1477333920,
1477333980, 1477334040, 1477334100, 1477334160, 1477334220, 1477334280,
1477334340, 1477334400, 1477334460, 1477334520, 1477334580, 1477334640,
1477334700, 1477334760, 1477334820, 1477334880, 1477334940, 1477335000,
1477335060, 1477335120, 1477335180, 1477335240, 1477335300, 1477335360,
1477335420, 1477335480, 1477335540, 1477335600, 1477335660, 1477335720,
1477335780, 1477335840, 1477335900, 1477335960, 1477336020, 1477336080,
1477336140, 1477336200, 1477336260, 1477336320, 1477336440, 1477336500,
1477336560, 1477336620, 1477336680, 1477336740, 1477336800, 1477336860,
1477336920, 1477336980), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
    NG1.Open = c(2.953, 2.952, 2.954, 2.953, 2.95, 2.946, 2.94,
    2.938, 2.936, 2.941, 2.938, 2.937, 2.936, 2.929, 2.927, 2.927,
    2.927, 2.928, 2.93, 2.929, 2.93, 2.928, 2.927, 2.927, 2.929,
    2.928, 2.929, 2.928, 2.925, 2.924, 2.919, 2.911, 2.911, 2.913,
    2.914, 2.905, 2.892, 2.893, 2.887, 2.893, 2.894, 2.897, 2.897,
    2.897, 2.893, 2.893, 2.873, 2.878, 2.883, 2.871, 2.864, 2.865,
    2.872, 2.877, 2.88, 2.884, 2.886, 2.889, 2.887, 2.891, 2.894,
    2.894, 2.885, 2.884, 2.885, 2.889, 2.886, 2.89, 2.891, 2.892,
    2.892, 2.891, 2.893, 2.89, 2.896, 2.892, 2.892, 2.897, 2.893,
    2.898, 2.903, 2.902, 2.898, 2.898, 2.899, 2.902, 2.898, 2.893,
    2.892, 2.89, 2.891, 2.891, 2.891, 2.887, 2.887, 2.873, 2.89,
    2.889, 2.889, 2.88, 2.877, 2.879, 2.882, 2.876, 2.877, 2.88,
    2.873, 2.873, 2.872, 2.872, 2.871, 2.868, 2.872, 2.879, 2.883,
    2.881, 2.882, 2.883, 2.883, 2.885, 2.886, 2.887, 2.885, 2.885,
    2.89, 2.887, 2.887, 2.885, 2.884, 2.884, 2.883, 2.885, 2.884,
    2.884, 2.885, 2.879, 2.877, 2.875, 2.875, 2.879, 2.881, 2.881,
    2.884, 2.882, 2.882, 2.881, 2.878, 2.879, 2.877, 2.876, 2.875,
    2.873, 2.874, 2.875, 2.875, 2.873, 2.874, 2.875, 2.877, 2.876,
    2.876, 2.874, 2.873, 2.872, 2.874, 2.871, 2.863, 2.861, 2.86,
    2.859, 2.855, 2.853, 2.851, 2.854, 2.857, 2.86, 2.861, 2.862,
    2.862, 2.864, 2.865, 2.868, 2.867, 2.869, 2.869, 2.873, 2.872,
    2.873, 2.873, 2.878, 2.879, 2.875, 2.874, 2.869, 2.867, 2.865,
    2.867, 2.867, 2.865, 2.866, 2.865, 2.867, 2.866, 2.867, 2.867,
    2.871, 2.877, 2.876, 2.881, 2.886, 2.889, 2.892, 2.895, 2.896,
    2.893, 2.889, 2.89, 2.89, 2.89, 2.892, 2.89, 2.888, 2.89,
    2.889, 2.888, 2.889, 2.888, 2.888, 2.887, 2.889, 2.888, 2.889,
    2.888, 2.882, 2.883, 2.883, 2.885, 2.883, 2.881, 2.878, 2.879,
    2.88, 2.883, 2.875, 2.87, 2.865, 2.86, 2.862, 2.864, 2.861,
    2.863, 2.858, 2.855, 2.852, 2.854, 2.858, 2.856, 2.858, 2.86,
    2.859, 2.859, 2.861, 2.86, 2.861, 2.86, 2.86, 2.858, 2.856,
    2.853, 2.851, 2.851, 2.852, 2.853, 2.852, 2.851, 2.856, 2.858,
    2.857, 2.86, 2.859, 2.856, 2.854, 2.853, 2.85, 2.85, 2.843,
    2.837, 2.838, 2.84, 2.84, 2.84, 2.839, 2.838, 2.84, 2.832,
    2.832, 2.833, 2.832, 2.832, 2.836, 2.838, 2.837, 2.833, 2.836,
    2.834, 2.832, 2.835, 2.84, 2.842, 2.844, 2.843, 2.841, 2.839,
    2.838, 2.837, 2.838, 2.838, 2.839, 2.839, 2.839, 2.844, 2.843,
    2.844, 2.843, 2.845, 2.845, 2.846, 2.847, 2.848, 2.848, 2.846,
    2.847, 2.848, 2.846, 2.847, 2.846, 2.845, 2.844, 2.848, 2.848,
    2.849, 2.847, 2.847, 2.847, 2.846, 2.846, 2.847, 2.846, 2.846,
    2.846, 2.846, 2.846, 2.845, 2.844, 2.841, 2.84, 2.841, 2.842,
    2.841), NG1.High = c(2.953, 2.957, 2.955, 2.953, 2.951, 2.947,
    2.94, 2.939, 2.941, 2.941, 2.94, 2.937, 2.936, 2.929, 2.928,
    2.928, 2.93, 2.933, 2.932, 2.93, 2.93, 2.928, 2.927, 2.93,
    2.929, 2.931, 2.932, 2.928, 2.925, 2.926, 2.92, 2.912, 2.914,
    2.914, 2.914, 2.905, 2.894, 2.895, 2.892, 2.898, 2.898, 2.898,
    2.902, 2.898, 2.894, 2.893, 2.881, 2.884, 2.883, 2.871, 2.87,
    2.872, 2.879, 2.882, 2.885, 2.889, 2.89, 2.889, 2.893, 2.898,
    2.895, 2.894, 2.887, 2.887, 2.89, 2.889, 2.891, 2.892, 2.893,
    2.892, 2.893, 2.894, 2.893, 2.897, 2.896, 2.892, 2.897, 2.897,
    2.9, 2.905, 2.903, 2.902, 2.9, 2.9, 2.902, 2.902, 2.898,
    2.893, 2.892, 2.892, 2.891, 2.891, 2.891, 2.891, 2.888, 2.891,
    2.89, 2.893, 2.889, 2.882, 2.88, 2.883, 2.882, 2.878, 2.881,
    2.882, 2.876, 2.873, 2.873, 2.875, 2.871, 2.871, 2.88, 2.884,
    2.884, 2.882, 2.883, 2.884, 2.885, 2.887, 2.888, 2.887, 2.886,
    2.891, 2.891, 2.889, 2.887, 2.887, 2.885, 2.884, 2.885, 2.886,
    2.884, 2.889, 2.886, 2.879, 2.877, 2.876, 2.878, 2.882, 2.882,
    2.884, 2.884, 2.884, 2.882, 2.881, 2.879, 2.879, 2.877, 2.877,
    2.876, 2.874, 2.874, 2.875, 2.875, 2.875, 2.875, 2.877, 2.877,
    2.877, 2.876, 2.874, 2.873, 2.874, 2.874, 2.872, 2.864, 2.864,
    2.862, 2.86, 2.856, 2.853, 2.858, 2.861, 2.862, 2.863, 2.862,
    2.863, 2.867, 2.867, 2.867, 2.868, 2.868, 2.869, 2.875, 2.874,
    2.873, 2.873, 2.878, 2.881, 2.879, 2.875, 2.874, 2.87, 2.869,
    2.867, 2.868, 2.867, 2.865, 2.866, 2.867, 2.869, 2.867, 2.869,
    2.875, 2.877, 2.878, 2.881, 2.887, 2.891, 2.896, 2.895, 2.897,
    2.896, 2.893, 2.892, 2.892, 2.89, 2.895, 2.893, 2.89, 2.89,
    2.89, 2.89, 2.89, 2.89, 2.888, 2.888, 2.889, 2.89, 2.888,
    2.89, 2.889, 2.891, 2.886, 2.884, 2.886, 2.883, 2.881, 2.879,
    2.88, 2.884, 2.883, 2.875, 2.871, 2.865, 2.864, 2.865, 2.864,
    2.863, 2.865, 2.858, 2.855, 2.855, 2.858, 2.859, 2.858, 2.859,
    2.86, 2.86, 2.86, 2.861, 2.861, 2.862, 2.861, 2.86, 2.858,
    2.856, 2.853, 2.852, 2.853, 2.855, 2.853, 2.852, 2.857, 2.861,
    2.86, 2.86, 2.86, 2.859, 2.856, 2.856, 2.853, 2.852, 2.85,
    2.843, 2.839, 2.84, 2.841, 2.843, 2.84, 2.839, 2.84, 2.84,
    2.833, 2.835, 2.835, 2.834, 2.838, 2.838, 2.841, 2.838, 2.836,
    2.836, 2.835, 2.836, 2.842, 2.844, 2.845, 2.845, 2.844, 2.842,
    2.839, 2.838, 2.838, 2.839, 2.839, 2.84, 2.841, 2.844, 2.844,
    2.844, 2.845, 2.846, 2.846, 2.847, 2.847, 2.849, 2.849, 2.848,
    2.847, 2.847, 2.848, 2.847, 2.848, 2.847, 2.845, 2.847, 2.849,
    2.85, 2.849, 2.848, 2.847, 2.848, 2.847, 2.847, 2.847, 2.846,
    2.847, 2.847, 2.846, 2.847, 2.845, 2.844, 2.841, 2.841, 2.842,
    2.842, 2.841), NG1.Low = c(2.951, 2.952, 2.952, 2.95, 2.945,
    2.939, 2.937, 2.935, 2.935, 2.936, 2.937, 2.93, 2.927, 2.926,
    2.924, 2.925, 2.926, 2.928, 2.929, 2.928, 2.928, 2.925, 2.926,
    2.927, 2.924, 2.927, 2.928, 2.924, 2.924, 2.919, 2.91, 2.902,
    2.91, 2.911, 2.903, 2.891, 2.888, 2.887, 2.886, 2.891, 2.894,
    2.895, 2.896, 2.893, 2.891, 2.872, 2.872, 2.878, 2.871, 2.852,
    2.864, 2.863, 2.872, 2.876, 2.876, 2.883, 2.886, 2.885, 2.887,
    2.891, 2.892, 2.886, 2.883, 2.878, 2.884, 2.884, 2.885, 2.89,
    2.89, 2.89, 2.89, 2.891, 2.889, 2.889, 2.893, 2.89, 2.891,
    2.893, 2.893, 2.897, 2.901, 2.896, 2.896, 2.898, 2.899, 2.898,
    2.893, 2.886, 2.89, 2.889, 2.89, 2.89, 2.887, 2.879, 2.87,
    2.87, 2.886, 2.888, 2.878, 2.877, 2.877, 2.879, 2.877, 2.874,
    2.876, 2.871, 2.87, 2.87, 2.87, 2.87, 2.866, 2.867, 2.872,
    2.879, 2.881, 2.881, 2.882, 2.882, 2.882, 2.885, 2.886, 2.884,
    2.884, 2.885, 2.887, 2.887, 2.885, 2.883, 2.882, 2.883, 2.881,
    2.883, 2.882, 2.883, 2.878, 2.875, 2.875, 2.875, 2.875, 2.879,
    2.879, 2.881, 2.882, 2.881, 2.881, 2.877, 2.876, 2.877, 2.875,
    2.874, 2.874, 2.872, 2.873, 2.874, 2.872, 2.871, 2.872, 2.875,
    2.876, 2.876, 2.873, 2.871, 2.872, 2.871, 2.871, 2.861, 2.857,
    2.86, 2.859, 2.854, 2.848, 2.85, 2.851, 2.854, 2.857, 2.86,
    2.861, 2.86, 2.862, 2.864, 2.865, 2.866, 2.867, 2.868, 2.868,
    2.872, 2.871, 2.872, 2.873, 2.876, 2.872, 2.872, 2.869, 2.866,
    2.863, 2.863, 2.866, 2.864, 2.864, 2.865, 2.864, 2.866, 2.866,
    2.866, 2.867, 2.87, 2.875, 2.875, 2.879, 2.884, 2.887, 2.892,
    2.891, 2.892, 2.887, 2.888, 2.89, 2.89, 2.889, 2.89, 2.888,
    2.888, 2.889, 2.887, 2.888, 2.887, 2.887, 2.887, 2.886, 2.889,
    2.886, 2.888, 2.879, 2.882, 2.883, 2.883, 2.883, 2.88, 2.878,
    2.878, 2.879, 2.88, 2.875, 2.868, 2.859, 2.86, 2.86, 2.862,
    2.86, 2.861, 2.856, 2.855, 2.852, 2.851, 2.854, 2.855, 2.856,
    2.858, 2.858, 2.857, 2.859, 2.86, 2.859, 2.86, 2.86, 2.856,
    2.857, 2.849, 2.851, 2.85, 2.849, 2.851, 2.851, 2.85, 2.851,
    2.854, 2.856, 2.857, 2.857, 2.857, 2.851, 2.853, 2.849, 2.849,
    2.842, 2.836, 2.835, 2.838, 2.838, 2.84, 2.838, 2.838, 2.838,
    2.83, 2.829, 2.83, 2.831, 2.832, 2.832, 2.834, 2.837, 2.831,
    2.83, 2.831, 2.827, 2.83, 2.835, 2.84, 2.842, 2.843, 2.84,
    2.839, 2.837, 2.837, 2.836, 2.838, 2.838, 2.837, 2.838, 2.836,
    2.843, 2.843, 2.843, 2.843, 2.845, 2.845, 2.846, 2.846, 2.846,
    2.845, 2.846, 2.847, 2.847, 2.845, 2.845, 2.845, 2.843, 2.844,
    2.848, 2.848, 2.847, 2.847, 2.846, 2.846, 2.846, 2.846, 2.846,
    2.846, 2.846, 2.846, 2.846, 2.844, 2.844, 2.84, 2.84, 2.84,
    2.84, 2.84, 2.84), NG1.Close = c(2.951, 2.955, 2.953, 2.95,
    2.946, 2.94, 2.939, 2.935, 2.94, 2.937, 2.937, 2.936, 2.929,
    2.926, 2.926, 2.927, 2.928, 2.93, 2.93, 2.93, 2.928, 2.927,
    2.926, 2.928, 2.928, 2.929, 2.928, 2.925, 2.924, 2.919, 2.911,
    2.911, 2.912, 2.913, 2.904, 2.892, 2.894, 2.887, 2.892, 2.894,
    2.896, 2.896, 2.898, 2.893, 2.893, 2.872, 2.878, 2.884, 2.871,
    2.864, 2.867, 2.872, 2.878, 2.88, 2.885, 2.887, 2.889, 2.887,
    2.891, 2.893, 2.893, 2.886, 2.884, 2.886, 2.89, 2.886, 2.889,
    2.89, 2.892, 2.891, 2.891, 2.894, 2.89, 2.897, 2.893, 2.891,
    2.897, 2.893, 2.898, 2.902, 2.901, 2.899, 2.898, 2.899, 2.901,
    2.898, 2.893, 2.893, 2.89, 2.892, 2.89, 2.891, 2.887, 2.886,
    2.874, 2.889, 2.888, 2.888, 2.879, 2.877, 2.879, 2.883, 2.877,
    2.877, 2.881, 2.872, 2.873, 2.873, 2.872, 2.87, 2.868, 2.871,
    2.879, 2.883, 2.882, 2.881, 2.883, 2.883, 2.884, 2.885, 2.887,
    2.884, 2.885, 2.89, 2.887, 2.887, 2.885, 2.885, 2.884, 2.884,
    2.885, 2.883, 2.884, 2.885, 2.88, 2.876, 2.876, 2.875, 2.878,
    2.881, 2.88, 2.884, 2.882, 2.882, 2.881, 2.877, 2.878, 2.877,
    2.876, 2.875, 2.874, 2.874, 2.874, 2.874, 2.872, 2.873, 2.875,
    2.877, 2.876, 2.876, 2.874, 2.873, 2.872, 2.873, 2.872, 2.862,
    2.861, 2.86, 2.859, 2.855, 2.853, 2.851, 2.854, 2.857, 2.859,
    2.862, 2.861, 2.863, 2.865, 2.865, 2.867, 2.867, 2.868, 2.869,
    2.874, 2.873, 2.872, 2.873, 2.878, 2.878, 2.874, 2.873, 2.87,
    2.867, 2.863, 2.867, 2.868, 2.865, 2.865, 2.865, 2.867, 2.866,
    2.866, 2.866, 2.871, 2.876, 2.875, 2.881, 2.886, 2.888, 2.892,
    2.894, 2.896, 2.893, 2.888, 2.891, 2.89, 2.89, 2.892, 2.891,
    2.888, 2.889, 2.889, 2.889, 2.89, 2.888, 2.888, 2.888, 2.888,
    2.889, 2.888, 2.889, 2.882, 2.883, 2.883, 2.884, 2.883, 2.88,
    2.879, 2.879, 2.88, 2.883, 2.876, 2.87, 2.865, 2.86, 2.862,
    2.865, 2.862, 2.863, 2.858, 2.856, 2.852, 2.854, 2.857, 2.856,
    2.857, 2.859, 2.858, 2.859, 2.86, 2.86, 2.86, 2.86, 2.86,
    2.858, 2.857, 2.853, 2.851, 2.852, 2.852, 2.854, 2.851, 2.851,
    2.856, 2.859, 2.857, 2.86, 2.858, 2.857, 2.854, 2.853, 2.85,
    2.85, 2.843, 2.836, 2.838, 2.839, 2.839, 2.841, 2.84, 2.838,
    2.84, 2.832, 2.832, 2.834, 2.831, 2.832, 2.836, 2.838, 2.838,
    2.833, 2.836, 2.835, 2.831, 2.835, 2.841, 2.841, 2.844, 2.843,
    2.84, 2.839, 2.838, 2.837, 2.838, 2.838, 2.839, 2.839, 2.839,
    2.843, 2.844, 2.844, 2.843, 2.845, 2.845, 2.846, 2.847, 2.847,
    2.848, 2.845, 2.847, 2.847, 2.847, 2.847, 2.847, 2.846, 2.843,
    2.847, 2.849, 2.85, 2.847, 2.848, 2.847, 2.847, 2.847, 2.847,
    2.846, 2.846, 2.847, 2.846, 2.846, 2.845, 2.844, 2.841, 2.841,
    2.84, 2.842, 2.841, 2.841), NG1.Volume = c(24, 249, 57, 48,
    203, 515, 228, 78, 163, 142, 99, 362, 182, 228, 233, 227,
    142, 142, 107, 80, 18, 312, 66, 122, 248, 98, 179, 245, 278,
    654, 1055, 934, 203, 141, 704, 1052, 637, 510, 607, 452,
    107, 71, 252, 136, 105, 928, 586, 288, 700, 2230, 562, 412,
    517, 174, 288, 503, 302, 292, 290, 335, 166, 177, 316, 383,
    267, 119, 233, 70, 165, 60, 143, 94, 222, 259, 84, 77, 297,
    69, 201, 647, 87, 283, 161, 110, 87, 65, 215, 365, 64, 78,
    110, 19, 88, 461, 1188, 1024, 204, 119, 152, 100, 144, 76,
    129, 94, 50, 148, 315, 79, 237, 305, 327, 64, 171, 256, 73,
    15, 35, 51, 167, 85, 70, 60, 86, 259, 68, 40, 36, 161, 66,
    18, 147, 19, 43, 169, 205, 138, 55, 67, 45, 78, 98, 66, 15,
    56, 57, 59, 68, 31, 29, 105, 93, 258, 158, 86, 87, 231, 153,
    69, 26, 35, 106, 170, 24, 332, 141, 664, 324, 110, 141, 246,
    1005, 138, 389, 307, 115, 170, 104, 98, 449, 179, 127, 69,
    66, 196, 363, 52, 69, 29, 56, 199, 78, 48, 85, 71, 224, 78,
    70, 73, 12, 35, 78, 92, 49, 69, 212, 259, 78, 184, 319, 471,
    552, 130, 269, 55, 179, 62, 14, 23, 173, 117, 87, 116, 16,
    85, 39, 43, 21, 25, 33, 75, 75, 119, 319, 243, 57, 13, 52,
    140, 110, 33, 51, 84, 126, 290, 548, 325, 152, 87, 114, 47,
    338, 191, 182, 142, 147, 72, 88, 58, 44, 40, 17, 45, 112,
    41, 77, 139, 23, 222, 87, 94, 326, 51, 119, 130, 204, 204,
    139, 39, 62, 52, 140, 179, 686, 319, 558, 607, 217, 81, 302,
    175, 105, 60, 104, 653, 393, 145, 63, 86, 443, 376, 438,
    666, 272, 639, 2668, 3012, 917, 430, 172, 76, 169, 225, 119,
    26, 95, 49, 82, 121, 105, 157, 37, 55, 201, 73, 40, 96, 46,
    193, 88, 35, 46, 60, 36, 102, 95, 45, 52, 210, 60, 63, 60,
    28, 33, 57, 47, 36, 110, 8, 12, 48, 8, 87, 112, 105, 99,
    57, 64, 52, 11)), row.names = c(NA, -359L), class = "data.frame",
.Names = c("times",
"NG1.Open", "NG1.High", "NG1.Low", "NG1.Close", "NG1.Volume"))


NG1 <- xts(ts[,-1],ts[,1])


initDate <- Sys.Date()-1
initEq <- 5000
n <- 14
nSMA <- 200

currency("USD")
Sys.setenv(TZ="UTC")
symbols <- "NG1"
stock(symbols, currency="USD", multiplier=1)

strategy.st <- 'teststrat'
portfolio.st <- 'teststrat'
account.st <- 'teststrat'
initPortf(portfolio.st, symbols = symbols, initDate=initDate,currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
initEq=initEq, currency='USD')
initOrders(portfolio=portfolio.st, initDate=initDate)



strategy(name = strategy.st,
         store = TRUE)







add.indicator(
  strategy = strategy.st,
  name = 'RSI',
  arguments = list(price=quote(Cl(mktdata)),n=n),
  label = "rsi")

add.indicator(
  strategy = strategy.st,
  name = 'SMA',
  arguments = list(x=quote(Cl(mktdata)),n=nSMA),
  label = 'sma'
)


add.signal(
  strategy = strategy.st,
  name = 'sigThreshold',
  arguments=list(
    threshold = 30,
    column = "rsi",
    relationship="lt",
    cross = TRUE),
  label = "RSI_long"
)

add.signal(
  strategy = strategy.st,
  name = 'sigThreshold',
  arguments=list(
    threshold = 70,
    column = "rsi",
    relationship="gt",
    cross = TRUE),
  label = "RSI_short"
)



add.rule(
  strategy=strategy.st,
  name='ruleSignal',
  arguments=list(
    sigcol='RSI_long',
    sigval = TRUE,
    orderside = 'long',
    ordertype='market',
    orderqty=1,
    replace=FALSE
  ),
  type='enter',
  label='Enterlong',
  path.dep = TRUE
)

add.rule(
  strategy=strategy.st,
  name='ruleSignal',
  arguments=list(
    sigcol='RSI_short',
    sigval = TRUE,
    orderside = 'short',
    ordertype='market',
    orderqty=1,
    replace=TRUE
  ),
  type='exit',
  label='Exitlong',
  path.dep = TRUE

)


t1<-Sys.time()
out<-applyStrategy(strategy=strategy.st,portfolios = portfolio.st)
t2<-Sys.time()
print(t2-t1)



On Mon, Oct 24, 2016 at 3:19 PM, Kevin Dhingra <
kevin.dhingra at appliedacademics.com> wrote:

> Hi Jon,
>
> As mentioned by Ilya, your arguments to SMA are incorrect. Also your
> program is missing the signal function. You need to convert your indicator
> into a signal using add.signal function before passing it to a rule. Try
> running the modified code -
>
> library(quantstrat)
> library(quantmod)
> library(tidyverse)
>
>
> ts <- structure(list(times = structure(c(1477312980, 1477313580,
>                                          1477314180,
>                                          1477314780, 1477315380,
> 1477315980, 1477316580, 1477317180, 1477317780,
>                                          1477318380, 1477318980,
> 1477319580, 1477320180, 1477320780, 1477321380,
>                                          1477321980, 1477322580,
> 1477323180, 1477323780, 1477324380, 1477324980,
>                                          1477325580, 1477326180,
> 1477326780, 1477327380, 1477327980, 1477328580,
>                                          1477329180, 1477329780,
> 1477330380, 1477330980, 1477331580, 1477332180,
>                                          1477332780, 1477333380,
> 1477333980, 1477334580), class = c("POSIXct",
>
>                           "POSIXt"), tzone = "UTC"), NG1.Open = c(2.954,
> 2.93, 2.936, 2.947,
>
>                                                                   2.951,
> 2.941, 2.929, 2.924, 2.893, 2.871, 2.891, 2.892, 2.898,
>
>                                                                   2.89,
> 2.88, 2.872, 2.885, 2.884, 2.879, 2.876, 2.876, 2.859,
>
>                                                                   2.864,
> 2.878, 2.866, 2.886, 2.892, 2.889, 2.878, 2.861, 2.859,
>
>                                                                   2.851,
> 2.859, 2.84, 2.836, 2.844, 2.839), NG1.High = c(2.959,
>
>
>                                              2.937, 2.954, 2.96, 2.957,
> 2.941, 2.932, 2.926, 2.902, 2.893,
>
>
>                                              2.898, 2.9, 2.905, 2.893,
> 2.883, 2.885, 2.891, 2.889, 2.884,
>
>
>                                              2.877, 2.877, 2.867, 2.878,
> 2.881, 2.887, 2.897, 2.893, 2.891,
>
>
>                                              2.884, 2.865, 2.862, 2.861,
> 2.859, 2.843, 2.845, 2.845, 2.842
>
>                                                                   ),
> NG1.Low = c(2.929, 2.916, 2.931, 2.946, 2.935, 2.924, 2.924,
>
>
>      2.886, 2.871, 2.852, 2.878, 2.889, 2.886, 2.87, 2.87, 2.866,
>
>
>      2.882, 2.875, 2.875, 2.871, 2.857, 2.848, 2.864, 2.863, 2.864,
>
>
>      2.884, 2.886, 2.878, 2.859, 2.851, 2.849, 2.849, 2.835, 2.829,
>
>
>      2.827, 2.836, 2.836), NG1.Close = c(2.93, 2.936, 2.947, 2.951,
>
>
>                                          2.94, 2.93, 2.924, 2.892, 2.871,
> 2.891, 2.892, 2.898, 2.89, 2.879,
>
>
>                                          2.872, 2.884, 2.884, 2.878, 2.876,
> 2.876, 2.859, 2.865, 2.878,
>
>
>                                          2.865, 2.886, 2.892, 2.888, 2.879,
> 2.862, 2.858, 2.851, 2.858,
>
>
>                                          2.839, 2.836, 2.844, 2.839,
> 2.842), NG1.Volume = c(2347, 4491,
>
>
>
>                 2793, 1124, 1624, 1864, 1646, 6497, 3625, 5570, 2231, 1506,
> 2084,
>
>
>
>                 3443, 1372, 1464, 931, 906, 557, 1266, 2047, 3021, 1206,
> 938,
>
>
>
>                 1375, 1928, 582, 1203, 1810, 1309, 803, 1368, 3141, 2227,
> 9590,
>
>
>
>                 1067, 128)), row.names = c(NA, -37L), class = "data.frame",
> .Names =
>                   c("times",
>                     "NG1.Open", "NG1.High", "NG1.Low", "NG1.Close",
> "NG1.Volume"))
>
> NG1 <- xts(ts[,-1],ts[,1])
>
>
> initDate <- index(NG1)[1]
> initEq <- 5000
> n <- 14
>
> currency("USD")
> Sys.setenv(TZ="UTC")
> symbols <- "NG1"
> stock(symbols, currency="USD", multiplier=1)
>
> strategy.st <- 'teststrat'
> portfolio.st <- 'teststrat'
> account.st <- 'teststrat'
> initPortf(portfolio.st, symbols = symbols, initDate=initDate,currency='
> USD')
> initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
>          initEq=initEq, currency='USD')
> initOrders(portfolio=portfolio.st, initDate=initDate)
>
>
>
> strategy(name = strategy.st,
>          store = TRUE)
>
> add.indicator(
>   strategy = strategy.st,
>   name = 'RSI',
>   arguments = list(price=quote(Cl(mktdata)),n=n),
>   label = "rsi")
>
>
>
> add.signal(strategy.st, name="sigThreshold",
>            arguments=list(column="rsi", threshold= 40,
>                           relationship="lt", cross=FALSE),
>            label="RSI_long")
>
> add.rule(
>   strategy=strategy.st,
>   name='ruleSignal',
>   arguments=list(
>     sigcol='RSI_long',
>     sigval = TRUE,
>     orderside = 'long',
>     ordertype='market',
>     orderqty=1,
>     replace=FALSE
>   ),
>   type='enter',
>   label='Enterlong',
>   path.dep = TRUE
> )
>
>
>
>
> t1<-Sys.time()
> out<-applyStrategy(strategy=strategy.st,portfolios = portfolio.st)
> t2<-Sys.time()
> print(t2-t1)
>
> On Mon, Oct 24, 2016 at 3:07 PM, Ilya Kipnis <ilya.kipnis at gmail.com>
> wrote:
>
>> Hi Jon,
>>
>> First off, check the parameters on your add.indicator call for your SMA
>> function.
>>
>> Secondly, your data is only 37 observations long and you have a setting of
>> 200.
>>
>> Please fix these two issues.
>>
>> -Ilya
>>
>> On Mon, Oct 24, 2016 at 2:55 PM, Jon Golenbock <jongolenbock at gmail.com>
>> wrote:
>>
>> > Hi folks,
>> >
>> > new to this mailing list and not very proficient with R in general yet,
>> so
>> > apologies in advance.
>> >
>> > all of the demos I could see were using stock data pulled from
>> > yahoo/google, etc -- mine is coming from bloomberg. I did my best to
>> > replicate the type of object that getsymbols() seems to create.
>> >
>> > everything seems to be working alright until I actually get to
>> > applystrategy(), where I am getting an error that I imagine, while not
>> > particularly helpful to me, will be completely obvious to somebody with
>> a
>> > bit more experience. the error i'm receiving is
>> >
>> > Error in n < 1 :
>> >   comparison (3) is possible only for atomic and list types
>> >
>> > code below. Any help is greatly appreciated and apologies for all the
>> rules
>> > I am surely breaking, I'll plead first-timer on this one.
>> >
>> >
>> >
>> > library(quantstrat)
>> > library(quantmod)
>> > library(tidyverse)
>> >
>> >
>> > ts <- structure(list(times = structure(c(1477312980, 1477313580,
>> > 1477314180,
>> > 1477314780, 1477315380, 1477315980, 1477316580, 1477317180, 1477317780,
>> > 1477318380, 1477318980, 1477319580, 1477320180, 1477320780, 1477321380,
>> > 1477321980, 1477322580, 1477323180, 1477323780, 1477324380, 1477324980,
>> > 1477325580, 1477326180, 1477326780, 1477327380, 1477327980, 1477328580,
>> > 1477329180, 1477329780, 1477330380, 1477330980, 1477331580, 1477332180,
>> > 1477332780, 1477333380, 1477333980, 1477334580), class = c("POSIXct",
>> > "POSIXt"), tzone = "UTC"), NG1.Open = c(2.954, 2.93, 2.936, 2.947,
>> > 2.951, 2.941, 2.929, 2.924, 2.893, 2.871, 2.891, 2.892, 2.898,
>> > 2.89, 2.88, 2.872, 2.885, 2.884, 2.879, 2.876, 2.876, 2.859,
>> > 2.864, 2.878, 2.866, 2.886, 2.892, 2.889, 2.878, 2.861, 2.859,
>> > 2.851, 2.859, 2.84, 2.836, 2.844, 2.839), NG1.High = c(2.959,
>> > 2.937, 2.954, 2.96, 2.957, 2.941, 2.932, 2.926, 2.902, 2.893,
>> > 2.898, 2.9, 2.905, 2.893, 2.883, 2.885, 2.891, 2.889, 2.884,
>> > 2.877, 2.877, 2.867, 2.878, 2.881, 2.887, 2.897, 2.893, 2.891,
>> > 2.884, 2.865, 2.862, 2.861, 2.859, 2.843, 2.845, 2.845, 2.842
>> > ), NG1.Low = c(2.929, 2.916, 2.931, 2.946, 2.935, 2.924, 2.924,
>> > 2.886, 2.871, 2.852, 2.878, 2.889, 2.886, 2.87, 2.87, 2.866,
>> > 2.882, 2.875, 2.875, 2.871, 2.857, 2.848, 2.864, 2.863, 2.864,
>> > 2.884, 2.886, 2.878, 2.859, 2.851, 2.849, 2.849, 2.835, 2.829,
>> > 2.827, 2.836, 2.836), NG1.Close = c(2.93, 2.936, 2.947, 2.951,
>> > 2.94, 2.93, 2.924, 2.892, 2.871, 2.891, 2.892, 2.898, 2.89, 2.879,
>> > 2.872, 2.884, 2.884, 2.878, 2.876, 2.876, 2.859, 2.865, 2.878,
>> > 2.865, 2.886, 2.892, 2.888, 2.879, 2.862, 2.858, 2.851, 2.858,
>> > 2.839, 2.836, 2.844, 2.839, 2.842), NG1.Volume = c(2347, 4491,
>> > 2793, 1124, 1624, 1864, 1646, 6497, 3625, 5570, 2231, 1506, 2084,
>> > 3443, 1372, 1464, 931, 906, 557, 1266, 2047, 3021, 1206, 938,
>> > 1375, 1928, 582, 1203, 1810, 1309, 803, 1368, 3141, 2227, 9590,
>> > 1067, 128)), row.names = c(NA, -37L), class = "data.frame", .Names =
>> > c("times",
>> > "NG1.Open", "NG1.High", "NG1.Low", "NG1.Close", "NG1.Volume"))
>> >
>> > NG1 <- xts(ts[,-1],ts[,1])
>> >
>> >
>> > initDate <- Sys.Date()-1
>> > initEq <- 5000
>> > n <- 14
>> > nSMA <- 200
>> >
>> > currency("USD")
>> > Sys.setenv(TZ="UTC")
>> > symbols <- "NG1"
>> > stock(symbols, currency="USD", multiplier=1)
>> >
>> > strategy.st <- 'teststrat'
>> > portfolio.st <- 'teststrat'
>> > account.st <- 'teststrat'
>> > initPortf(portfolio.st, symbols = symbols, initDate=initDate,currency='
>> > USD')
>> > initAcct(account.st, portfolios=portfolio.st, initDate=initDate,
>> > initEq=initEq, currency='USD')
>> > initOrders(portfolio=portfolio.st, initDate=initDate)
>> >
>> >
>> >
>> > strategy(name = strategy.st,
>> >          store = TRUE)
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > add.indicator(
>> >   strategy = strategy.st,
>> >   name = 'RSI',
>> >   arguments = list(price=quote(Cl(mktdata)),n=n),
>> >   label = "rsi")
>> >
>> > add.indicator(
>> >   strategy = strategy.st,
>> >   name = 'SMA',
>> >   arguments = list(x=quote(Cl(mktdata)),n=SMA),
>> >   label = 'sma'
>> > )
>> >
>> >
>> >
>> > add.rule(
>> >   strategy=strategy.st,
>> >   name='ruleSignal',
>> >   arguments=list(
>> >     sigcol='RSI_long',
>> >     sigval = TRUE,
>> >     orderside = 'long',
>> >     ordertype='market',
>> >     orderqty=1,
>> >     replace=FALSE
>> >   ),
>> >   type='enter',
>> >   label='Enterlong',
>> >   path.dep = TRUE
>> > )
>> >
>> > add.rule(
>> >   strategy=strategy.st,
>> >   name='ruleSignal',
>> >   arguments=list(
>> >     sigcol='RSI_short',
>> >     sigval = TRUE,
>> >     orderside = 'short',
>> >     ordertype='market',
>> >     orderqty=1,
>> >     replace=TRUE
>> >   ),
>> >   type='exit',
>> >   label='Exitlong',
>> >   path.dep = TRUE
>> >
>> > )
>> >
>> >
>> > t1<-Sys.time()
>> > out<-applyStrategy(strategy=strategy.st,portfolios = portfolio.st)
>> > t2<-Sys.time()
>> > print(t2-t1)
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-SIG-Finance at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> > -- Subscriber-posting only. If you want to post, subscribe first.
>> > -- Also note that this is not the r-help list where general R questions
>> > should go.
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list