我试图找到以下参数的交集:
ma.20 <- SMA(x[,5], 20)
ma.50 <- SMA(x[,5], 50)
price.b <- ifelse(sign(x[,5])- runMax(x[,1], 20) | sign(runMin(x[,2],20)-x[,5])==1, 1, 0)
ma.break <- sign(x[,5]-ma.50)
rev.ma <- sign(ma.50-ma.20)
sig <- union(which(!p.break[1,]==0), which(!ma.break[1,]==0), which(!rev.ma<0)) ## Retrieves signals
}
基本上,如果其中一个参数成立,我试图检索列号:( p.break [,1] == 0或ma.break [1,] == 0或rev.ma [ 1,] == 0),但上面的命令返回:
Error in base::union(x, y, ...) :
unused argument (c(66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223))
我非常感谢一些建议。我使用TTR包来计算SMA。附件是我的意思:
structure(c(1.0854, 1.0854, 1.0854, 1.0781, 1.0711, 1.0716, 1.0771,
1.0803, 1.0803, 1.0803, 1.0848, 1.082, 1.0805, 1.0835, 1.0855,
1.0855, 1.0855, 1.0869, 1.086, 1.0877, 1.0778, 1.0789, 1.0789,
1.0789, 1.079, 1.0819, 1.0851, 1.087, 1.081, 1.081, 1.081, 1.0815,
1.0886, 1.0904, 1.107, 1.1109, 1.1109, 1.1109, 1.1087, 1.1162,
1.1161, 1.1274, 1.1214, 1.1214, 1.1214, 1.1128, 1.1124, 1.1106,
1.1071, 1.1067, 1.1067, 1.1067, 1.1003, 1.099, 1.0957, 1.0987,
1.0912, 1.0912, 1.0912, 1.0859, 1.0834, 1.0826, 1.0854, 1.0904,
1.0904, 1.0904, 1.094, 1.0994, 1.0946, 1.0822, 1.108, 1.108,
1.108, 1.1078, 1.1072, 1.1058, 1.1206, 1.1256, 1.1256, 1.1256,
1.1235, 1.1189, 1.116, 1.1144, 1.1154, 1.1154, 1.1154, 1.1153,
1.1169, 1.1284, 1.131, 1.1335, 1.1335, 1.1335, 1.1358, 1.1336,
1.1327, 1.1338, 1.1349, 1.1349, 1.1349, 1.1372, 1.1346, 1.1268,
1.1234, 1.1246, 1.1246, 1.1246, 1.1274, 1.1304, 1.1291, 1.127,
1.1218, 1.1218, 1.1218, 1.1217, 1.1256, 1.1272, 1.1296, 1.1348,
1.1348, 1.1348, 1.1431, 1.1496, 1.1467, 1.1386, 1.1387, 1.1387,
1.1387, 1.1376, 1.1359, 1.1369, 1.1371, 1.1283, 1.1283, 1.1283,
1.1302, 1.1302, 1.1214, 1.118, 1.1196, 1.1196, 1.1196, 1.1188,
1.1133, 1.1129, 1.115, 1.1111, 1.1111, 1.1111, 1.1098, 1.1122,
1.1114, 1.1145, 1.1137, 1.1137, 1.1137, 1.1326, 1.1339, 1.1355,
1.1306, 1.1246, 1.1246, 1.1246, 1.1232, 1.1189, 1.119, 1.1131,
1.1223, 1.1223, 1.1223, 1.1281, 1.1242, 1.1237, 1.1296, 1.0913,
1.0913, 1.0913, 1.0971, 1.101, 1.1049, 1.1024, 1.1072, 1.1072,
1.1072, 1.1098, 1.1062, 1.1029, 1.1053, 1.1002, 1.1002, 1.1002,
1.1016, 1.1052, 1.1042, 1.1088, 1.1025, 1.1025, 1.1025, 1.1038,
1.1, 1.0982, 1.098, 1.0956, 1.0956, 1.0956, 1.0952, 1.0978, 1.0961,
1.1053, 1.1073, 1.1073, 1.1073, 1.1155, 1.1159, 1.1141, 1.1114,
1.1046, 1.1046, 1.1046, 1.1072, 1.1071, 1.1113, 1.1136, 1.1131,
1.1131, 1.1131, 1.1154, 1.1178, 1.1242, 1.1286, 1.1304, 1.1304,
1.1304, 1.1271, 1.1303, 1.1245, 1.1259, 1.1181, 1.1181, 1.1181,
1.1158, 1.1153, 1.0867, 1.0867, 1.0867, 1.0946, 1.0839, 1.0799,
1.094, 1.0934, 1.0934, 1.0934, 1.097, 1.09, 1.0888, 1.0943, 1.0985,
1.0985, 1.0985, 1.0942, 1.0939, 1.0976, 1.0921, 1.0877, 1.0877,
1.0877, 1.0857, 1.0874, 1.0917, 1.0968, 1.0949, 1.0949, 1.0949,
1.0913, 1.094, 1.1146, 1.1239, 1.1246, 1.1246, 1.1246, 1.1216,
1.1338, 1.1311, 1.1376, 1.1334, 1.1334, 1.1334, 1.1261, 1.1193,
1.1179, 1.115, 1.1139, 1.1139, 1.1139, 1.1135, 1.1053, 1.1046,
1.105, 1.1068, 1.1068, 1.1068, 1.0963, 1.0894, 1.0881, 1.0973,
1.1043, 1.1043, 1.1043, 1.1026, 1.1058, 1.1035, 1.1218, 1.121,
1.121, 1.121, 1.1176, 1.1125, 1.1242, 1.1342, 1.1337, 1.1337,
1.1337, 1.1288, 1.126, 1.1224, 1.1188, 1.1181, 1.1181, 1.1181,
1.122, 1.1303, 1.1365, 1.1412, 1.1438, 1.1438, 1.1438, 1.1413,
1.1405, 1.1432, 1.1454, 1.1419, 1.1419, 1.1419, 1.1447, 1.1465,
1.1391, 1.1295, 1.1317, 1.1317, 1.1317, 1.1332, 1.1385, 1.1388,
1.1398, 1.1309, 1.1309, 1.1309, 1.1278, 1.134, 1.1362, 1.1368,
1.1459, 1.1459, 1.1459, 1.1536, 1.1616, 1.1529, 1.1494, 1.1479,
1.1479, 1.1479, 1.142, 1.141, 1.1447, 1.1429, 1.138, 1.138, 1.138,
1.1342, 1.1349, 1.1316, 1.123, 1.1237, 1.1237, 1.1237, 1.1243,
1.1227, 1.1167, 1.1217, 1.1201, 1.1201, 1.1201, 1.1145, 1.1173,
1.1194, 1.122, 1.1374, 1.1374, 1.1374, 1.1393, 1.1381, 1.1411,
1.1416, 1.1321, 1.1321, 1.1321, 1.1303, 1.1298, 1.1298, 1.1295,
1.1296, 1.1296, 1.1296, 1.1382, 1.135, 1.1338, 1.1421, 1.1428,
1.1428, 1.1428, 1.1084, 1.1112, 1.113, 1.1155, 1.1169, 1.1169,
1.1169, 1.116, 1.1186, 1.1112, 1.1107, 1.112, 1.112, 1.112, 1.1075,
1.1126, 1.112, 1.1165, 1.1149, 1.1149, 1.1149, 1.1084, 1.1081,
1.103, 1.106, 1.1041, 1.1041, 1.1041, 1.0999, 1.103, 1.1065,
1.1119, 1.1197, 1.1197, 1.1197, 1.1184, 1.1234, 1.1227, 1.1156,
1.1161, 1.1161, 1.1161, 1.1105, 1.1123, 1.119, 1.1192, 1.1221,
1.1221, 1.1221, 1.1204, 1.1323, 1.1316, 1.1366, 1.136, 1.136,
1.136, 1.1334, 1.1355, 1.1312, 1.1298, 1.1341, 1.1341, 1.1341,
1.1208, 1.1192, 1.0854, 1.0854, 1.0854, 1.0781, 1.0711, 1.0716,
1.0771, 1.0803, 1.0803, 1.0803, 1.0848, 1.082, 1.0805, 1.0835,
1.0855, 1.0855, 1.0855, 1.0869, 1.086, 1.0877, 1.0778, 1.0789,
1.0789, 1.0789, 1.079, 1.0819, 1.0851, 1.087, 1.081, 1.081, 1.081,
1.0815, 1.0886, 1.0904, 1.107, 1.1109, 1.1109, 1.1109, 1.1087,
1.1162, 1.1161, 1.1274, 1.1214, 1.1214, 1.1214, 1.1128, 1.1124,
1.1106, 1.1071, 1.1067, 1.1067, 1.1067, 1.1003, 1.099, 1.0957,
1.0987, 1.0912, 1.0912, 1.0912, 1.0859, 1.0834, 1.0826, 1.0854,
1.0904, 1.0904, 1.0904, 1.094, 1.0994, 1.0946, 1.0822, 1.108,
1.108, 1.108, 1.1078, 1.1072, 1.1058, 1.1206, 1.1256, 1.1256,
1.1256, 1.1235, 1.1189, 1.116, 1.1144, 1.1154, 1.1154, 1.1154,
1.1153, 1.1169, 1.1284, 1.131, 1.1335, 1.1335, 1.1335, 1.1358,
1.1336, 1.1327, 1.1338, 1.1349, 1.1349, 1.1349, 1.1372, 1.1346,
1.1268, 1.1234, 1.1246, 1.1246, 1.1246, 1.1274, 1.1304, 1.1291,
1.127, 1.1218, 1.1218, 1.1218, 1.1217, 1.1256, 1.1272, 1.1296,
1.1348, 1.1348, 1.1348, 1.1431, 1.1496, 1.1467, 1.1386, 1.1387,
1.1387, 1.1387, 1.1376, 1.1359, 1.1369, 1.1371, 1.1283, 1.1283,
1.1283, 1.1302, 1.1302, 1.1214, 1.118, 1.1196, 1.1196, 1.1196,
1.1188, 1.1133, 1.1129, 1.115, 1.1111, 1.1111, 1.1111, 1.1098,
1.1122, 1.1114, 1.1145, 1.1137, 1.1137, 1.1137, 1.1326, 1.1339,
1.1355, 1.1306, 1.1246, 1.1246, 1.1246, 1.1232, 1.1189, 1.119,
1.1131, 1.1223, 1.1223, 1.1223, 1.1281, 1.1242, 1.1237, 1.1296,
1.0913, 1.0913, 1.0913, 1.0971, 1.101, 1.1049, 1.1024, 1.1072,
1.1072, 1.1072, 1.1098, 1.1062, 1.1029, 1.1053, 1.1002, 1.1002,
1.1002, 1.1016, 1.1052, 1.1042, 1.1088, 1.1025, 1.1025, 1.1025,
1.1038, 1.1, 1.0982, 1.098, 1.0956, 1.0956, 1.0956, 1.0952, 1.0978,
1.0961, 1.1053, 1.1073, 1.1073, 1.1073, 1.1155, 1.1159, 1.1141,
1.1114, 1.1046, 1.1046, 1.1046, 1.1072, 1.1071, 1.1113, 1.1136,
1.1131, 1.1131, 1.1131, 1.1154, 1.1178, 1.1242, 1.1286, 1.1304,
1.1304, 1.1304, 1.1271, 1.1303, 1.1245, 1.1259, 1.1181, 1.1181,
1.1181, 1.1158, 1.1153, 1.0856, 1.0856, 1.0856, 1.0831, 1.0748,
1.0781, 1.0932, 1.0922, 1.0922, 1.0922, 1.0859, 1.0858, 1.0877,
1.0865, 1.0916, 1.0916, 1.0916, 1.0892, 1.0908, 1.089, 1.0874,
1.0796, 1.0796, 1.0796, 1.0849, 1.087, 1.0893, 1.094, 1.0831,
1.0831, 1.0831, 1.0888, 1.0919, 1.1105, 1.1209, 1.1158, 1.1158,
1.1158, 1.1193, 1.1293, 1.1292, 1.1323, 1.1256, 1.1256, 1.1256,
1.1156, 1.1144, 1.1128, 1.1107, 1.113, 1.113, 1.113, 1.103, 1.102,
1.1013, 1.1018, 1.0934, 1.0934, 1.0934, 1.0873, 1.0868, 1.0868,
1.0957, 1.1005, 1.1005, 1.1005, 1.1014, 1.1011, 1.0999, 1.1177,
1.1156, 1.1156, 1.1156, 1.1103, 1.1109, 1.1224, 1.1318, 1.127,
1.127, 1.127, 1.1241, 1.1217, 1.1181, 1.1174, 1.1167, 1.1167,
1.1167, 1.1196, 1.1291, 1.1338, 1.138, 1.1391, 1.1391, 1.1391,
1.1391, 1.1384, 1.1399, 1.1378, 1.1399, 1.1399, 1.1399, 1.1408,
1.1386, 1.1274, 1.1268, 1.1284, 1.1284, 1.1284, 1.1313, 1.1358,
1.1297, 1.1288, 1.1222, 1.1222, 1.1222, 1.1268, 1.1297, 1.1322,
1.1352, 1.1451, 1.1451, 1.1451, 1.1534, 1.1496, 1.1487, 1.1405,
1.1404, 1.1404, 1.1404, 1.1383, 1.1372, 1.1426, 1.1377, 1.1309,
1.1309, 1.1309, 1.1321, 1.1313, 1.1216, 1.1203, 1.1224, 1.1224,
1.1224, 1.122, 1.1141, 1.1155, 1.1194, 1.1115, 1.1115, 1.1115,
1.1138, 1.1132, 1.1188, 1.1151, 1.1367, 1.1367, 1.1367, 1.1355,
1.1358, 1.1395, 1.1316, 1.1251, 1.1251, 1.1251, 1.1292, 1.1207,
1.126, 1.1225, 1.1277, 1.1277, 1.1277, 1.1314, 1.1242, 1.1296,
1.1385, 1.1117, 1.1117, 1.1117, 1.1025, 1.1065, 1.1125, 1.1106,
1.1136, 1.1136, 1.1136, 1.1154, 1.1076, 1.11, 1.1063, 1.1051,
1.1051, 1.1051, 1.1058, 1.1061, 1.109, 1.112, 1.1035, 1.1035,
1.1035, 1.1075, 1.1021, 1.1015, 1.1026, 1.0977, 1.0977, 1.0977,
1.0995, 1.0986, 1.1058, 1.1077, 1.1174, 1.1174, 1.1174, 1.1163,
1.1224, 1.1149, 1.113, 1.1086, 1.1086, 1.1086, 1.1088, 1.1117,
1.1176, 1.1137, 1.1162, 1.1162, 1.1162, 1.1184, 1.1279, 1.1289,
1.1354, 1.1325, 1.1325, 1.1325, 1.132, 1.1305, 1.1264, 1.1285,
1.1198, 1.1198, 1.1198, 1.1189, 1.1161, 1.0856, 1.0856, 1.0856,
1.0831, 1.0748, 1.0781, 1.0932, 1.0922, 1.0922, 1.0922, 1.0859,
1.0858, 1.0877, 1.0865, 1.0916, 1.0916, 1.0916, 1.0892, 1.0908,
1.089, 1.0874, 1.0796, 1.0796, 1.0796, 1.0849, 1.087, 1.0893,
1.094, 1.0831, 1.0831, 1.0831, 1.0888, 1.0919, 1.1105, 1.1209,
1.1158, 1.1158, 1.1158, 1.1193, 1.1293, 1.1292, 1.1323, 1.1256,
1.1256, 1.1256, 1.1156, 1.1144, 1.1128, 1.1107, 1.113, 1.113,
1.113, 1.103, 1.102, 1.1013, 1.1018, 1.0934, 1.0934, 1.0934,
1.0873, 1.0868, 1.0868, 1.0957, 1.1005, 1.1005, 1.1005, 1.1014,
1.1011, 1.0999, 1.1177, 1.1156, 1.1156, 1.1156, 1.1103, 1.1109,
1.1224, 1.1318, 1.127, 1.127, 1.127, 1.1241, 1.1217, 1.1181,
1.1174, 1.1167, 1.1167, 1.1167, 1.1196, 1.1291, 1.1338, 1.138,
1.1391, 1.1391, 1.1391, 1.1391, 1.1384, 1.1399, 1.1378, 1.1399,
1.1399, 1.1399, 1.1408, 1.1386, 1.1274, 1.1268, 1.1284, 1.1284,
1.1284, 1.1313, 1.1358, 1.1297, 1.1288, 1.1222, 1.1222, 1.1222,
1.1268, 1.1297, 1.1322, 1.1352, 1.1451, 1.1451, 1.1451, 1.1534,
1.1496, 1.1487, 1.1405, 1.1404, 1.1404, 1.1404, 1.1383, 1.1372,
1.1426, 1.1377, 1.1309, 1.1309, 1.1309, 1.1321, 1.1313, 1.1216,
1.1203, 1.1224, 1.1224, 1.1224, 1.122, 1.1141, 1.1155, 1.1194,
1.1115, 1.1115, 1.1115, 1.1138, 1.1132, 1.1188, 1.1151, 1.1367,
1.1367, 1.1367, 1.1355, 1.1358, 1.1395, 1.1316, 1.1251, 1.1251,
1.1251, 1.1292, 1.1207, 1.126, 1.1225, 1.1277, 1.1277, 1.1277,
1.1314, 1.1242, 1.1296, 1.1385, 1.1117, 1.1117, 1.1117, 1.1025,
1.1065, 1.1125, 1.1106, 1.1136, 1.1136, 1.1136, 1.1154, 1.1076,
1.11, 1.1063, 1.1051, 1.1051, 1.1051, 1.1058, 1.1061, 1.109,
1.112, 1.1035, 1.1035, 1.1035, 1.1075, 1.1021, 1.1015, 1.1026,
1.0977, 1.0977, 1.0977, 1.0995, 1.0986, 1.1058, 1.1077, 1.1174,
1.1174, 1.1174, 1.1163, 1.1224, 1.1149, 1.113, 1.1086, 1.1086,
1.1086, 1.1088, 1.1117, 1.1176, 1.1137, 1.1162, 1.1162, 1.1162,
1.1184, 1.1279, 1.1289, 1.1354, 1.1325, 1.1325, 1.1325, 1.132,
1.1305, 1.1264, 1.1285, 1.1198, 1.1198, 1.1198, 1.1189, 1.1161
), .Dim = c(243L, 5L), .Dimnames = list(NULL, c("EUR.OPEN", "EUR.HIGH",
"EUR.LOW", "EUR.CLOSE", "EUR.LAST")), index = structure(c(1451628000,
1451714400, 1451800800, 1451887200, 1451973600, 1452060000, 1452146400,
1452232800, 1452319200, 1452405600, 1452492000, 1452578400, 1452664800,
1452751200, 1452837600, 1452924000, 1453010400, 1453096800, 1453183200,
1453269600, 1453356000, 1453442400, 1453528800, 1453615200, 1453701600,
1453788000, 1453874400, 1453960800, 1454047200, 1454133600, 1454220000,
1454306400, 1454392800, 1454479200, 1454565600, 1454652000, 1454738400,
1454824800, 1454911200, 1454997600, 1455084000, 1455170400, 1455256800,
1455343200, 1455429600, 1455516000, 1455602400, 1455688800, 1455775200,
1455861600, 1455948000, 1456034400, 1456120800, 1456207200, 1456293600,
1456380000, 1456466400, 1456552800, 1456639200, 1456725600, 1456812000,
1456898400, 1456984800, 1457071200, 1457157600, 1457244000, 1457330400,
1457416800, 1457503200, 1457589600, 1457676000, 1457762400, 1457848800,
1457931600, 1458018000, 1458104400, 1458190800, 1458277200, 1458363600,
1458450000, 1458536400, 1458622800, 1458709200, 1458795600, 1458882000,
1458968400, 1459054800, 1459141200, 1459227600, 1459314000, 1459400400,
1459486800, 1459573200, 1459659600, 1459746000, 1459832400, 1459918800,
1460005200, 1460091600, 1460178000, 1460264400, 1460350800, 1460437200,
1460523600, 1460610000, 1460696400, 1460782800, 1460869200, 1460955600,
1461042000, 1461128400, 1461214800, 1461301200, 1461387600, 1461474000,
1461560400, 1461646800, 1461733200, 1461819600, 1461906000, 1461992400,
1462078800, 1462165200, 1462251600, 1462338000, 1462424400, 1462510800,
1462597200, 1462683600, 1462770000, 1462856400, 1462942800, 1463029200,
1463115600, 1463202000, 1463288400, 1463374800, 1463461200, 1463547600,
1463634000, 1463720400, 1463806800, 1463893200, 1463979600, 1464066000,
1464152400, 1464238800, 1464325200, 1464411600, 1464498000, 1464584400,
1464670800, 1464757200, 1464843600, 1464930000, 1465016400, 1465102800,
1465189200, 1465275600, 1465362000, 1465448400, 1465534800, 1465621200,
1465707600, 1465794000, 1465880400, 1465966800, 1466053200, 1466139600,
1466226000, 1466312400, 1466398800, 1466485200, 1466571600, 1466658000,
1466744400, 1466830800, 1466917200, 1467003600, 1467090000, 1467176400,
1467262800, 1467349200, 1467435600, 1467522000, 1467608400, 1467694800,
1467781200, 1467867600, 1467954000, 1468040400, 1468126800, 1468213200,
1468299600, 1468386000, 1468472400, 1468558800, 1468645200, 1468731600,
1468818000, 1468904400, 1468990800, 1469077200, 1469163600, 1469250000,
1469336400, 1469422800, 1469509200, 1469595600, 1469682000, 1469768400,
1469854800, 1469941200, 1470027600, 1470114000, 1470200400, 1470286800,
1470373200, 1470459600, 1470546000, 1470632400, 1470718800, 1470805200,
1470891600, 1470978000, 1471064400, 1471150800, 1471237200, 1471323600,
1471410000, 1471496400, 1471582800, 1471669200, 1471755600, 1471842000,
1471928400, 1472014800, 1472101200, 1472187600, 1472274000, 1472360400,
1472446800, 1472533200), tzone = "", tclass = c("POSIXct", "POSIXt"
)), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct",
"POSIXt"), .indexTZ = "", tzone = "", class = c("xts", "zoo"))