试图找出变量何时相互交叉或交叉(MA 交叉)
Trying to find out when variables cross up or down each other (MA crossover)
如果这不是正确的话题,我深表歉意。我只是对 R 中的以下问题感到非常困惑。我正在尝试为移动平均线交叉设置信号(20 天 MA 和 50 天 MA)。换句话说,我试图创建一个向量列表,当绿线越过紫色线时为 1,对于其他情况(紫色超过绿色)为 -1,否则为 0。
我的情节中似乎有大约 8 个交叉点,但是当我尝试使用 which
作为完整性检查时:
which(data[,5]==data[,6])
其中 data[5] 是绿线,而 data[6] 是紫色,我只返回第 551 行。因此,(我假设)我尝试使用的这条线没有工作:
signal <- ifelse((data[,5]==data[,6])&(data[,5]>data[,6]), 1, ifelse((data[,5]==data[,6])&(data[,5]<data[,6]), -1, 0)
非常感谢您的帮助!下面附上我的样本输出:
structure(c(1.3323, 1.3309, 1.3294, 1.3282, 1.327, 1.3249, 1.3226,
1.3202, 1.318, 1.3158, 1.3136, 1.3114, 1.3093, 1.3075, 1.3055,
1.3037, 1.3016, 1.2999, 1.2983, 1.2963, 1.2941, 1.2919, 1.2896,
1.2871, 1.2845, 1.2831, 1.2809, 1.2797, 1.2784, 1.2775, 1.2763,
1.2746, 1.2737, 1.2722, 1.2721, 1.2715, 1.2712, 1.2709, 1.2703,
1.2696, 1.2691, 1.269, 1.2691, 1.2696, 1.2696, 1.2694, 1.2694,
1.2685, 1.2679, 1.2667, 1.2651, 1.2642, 1.2626, 1.2617, 1.2597,
1.258, 1.2568, 1.2551, 1.2542, 1.2537, 1.2532, 1.2518, 1.2505,
1.2492, 1.2486, 1.2478, 1.2475, 1.2474, 1.2466, 1.2457, 1.2457,
1.2449, 1.2443, 1.2438, 1.2439, 1.2436, 1.2432, 1.2432, 1.2431,
1.242, 1.2407, 1.2399, 1.2389, 1.2374, 1.2358, 1.2346, 1.2332,
1.2317, 1.2305, 1.2295, 1.2281, 1.2267, 1.2248, 1.2223, 1.2193,
1.2162, 1.2131, 1.2101, 1.2064, 1.2036, 1.2004, 1.1971, 1.1939,
1.1908, 1.1879, 1.1836, 1.1787, 1.1741, 1.1703, 1.1662, 1.1623,
1.1587, 1.1558, 1.1537, 1.1513, 1.1497, 1.147, 1.1445, 1.1422,
1.14, 1.1388, 1.138, 1.1367, 1.136, 1.1349, 1.135, 1.1358, 1.1363,
1.1361, 1.1365, 1.1359, 1.1354, 1.1346, 1.1331, 1.1318, 1.1295,
1.1272, 1.1248, 1.1217, 1.1177, 1.1139, 1.1094, 1.1055, 1.1014,
1.0987, 1.0952, 1.0924, 1.0905, 1.0884, 1.0864, 1.0849, 1.0833,
1.0816, 1.0793, 1.0778, 1.077, 1.0776, 1.078, 1.0786, 1.0797,
1.0799, 1.0804, 1.0804, 1.0807, 1.0798, 1.0803, 1.0802, 1.0792,
1.0782, 1.077, 1.0767, 1.0766, 1.0769, 1.0782, 1.08, 1.0817,
1.0829, 1.084, 1.0858, 1.0887, 1.0917, 1.0947, 1.0976, 1.1004,
1.1038, 1.107, 1.1102, 1.1131, 1.1152, 1.117, 1.1185, 1.1192,
1.1196, 1.1191, 1.1179, 1.1166, 1.1155, 1.1144, 1.1142, 1.1139,
1.1137, 1.1133, 1.114, 1.1143, 1.1142, 1.1134, 1.1125, 1.1123,
1.1128, 1.1141, 1.1153, 1.117, 1.1188, 1.1203, 1.1218, 1.1231,
1.124, 1.1255, 1.1255, 1.1244, 1.1236, 1.1236, 1.1224, 1.1211,
1.1198, 1.1187, 1.1182, 1.1168, 1.1156, 1.1137, 1.1112, 1.1086,
1.1061, 1.1049, 1.1035, 1.1024, 1.1015, 1.1008, 1.1003, 1.1,
1.0992, 1.0986, 1.098, 1.0974, 1.0965, 1.096, 1.095, 1.0951,
1.0953, 1.0963, 1.0977, 1.0991, 1.1003, 1.1008, 1.1017, 1.103,
1.105, 1.1077, 1.11, 1.1116, 1.1132, 1.1142, 1.1155, 1.1177,
1.1193, 1.1203, 1.1212, 1.1219, 1.1227, 1.123, 1.1236, 1.1248,
1.126, 1.1272, 1.128, 1.129, 1.1286, 1.1264, 1.1244, 1.1238,
1.1237, 1.1238, 1.1239, 1.1236, 1.1234, 1.1237, 1.124, 1.1241,
1.1245, 1.1246, 1.1246, 1.1247, 1.1249, 1.1255, 1.1264, 1.1261,
1.1264, 1.1271, 1.1282, 1.129, 1.1284, 1.1275, 1.1266, 1.1256,
1.1243, 1.1232, 1.1222, 1.1213, 1.1198, 1.1179, 1.1159, 1.1129,
1.1098, 1.1065, 1.1029, 1.1, 1.0972, 1.094, 1.0904, 1.087, 1.0852,
1.0833, 1.0812, 1.0792, 1.0777, 1.0758, 1.0738, 1.0715, 1.0698,
1.0686, 1.0689, 1.0696, 1.07, 1.0708, 1.0722, 1.0729, 1.0739,
1.0755, 1.0769, 1.0782, 1.0786, 1.0798, 1.0811, 1.0827, 1.0842,
1.0859, 1.0878, 1.0898, 1.0912, 1.0928, 1.0924, 1.0923, 1.0923,
1.0915, 1.0903, 1.0903, 1.0899, 1.0893, 1.0889, 1.0887, 1.0889,
1.0892, 1.0891, 1.0888, 1.0887, 1.0883, 1.0874, 1.0868, 1.0866,
1.0864, 1.0868, 1.0867, 1.0869, 1.0878, 1.0894, 1.0908, 1.092,
1.0937, 1.0958, 1.0979, 1.1002, 1.1019, 1.1032, 1.1044, 1.1056,
1.1068, 1.1084, 1.1093, 1.1101, 1.1107, 1.1111, 1.1116, 1.1115,
1.1113, 1.1101, 1.1088, 1.108, 1.1071, 1.1057, 1.1043, 1.1035,
1.103, 1.1028, 1.1026, 1.1031, 1.1041, 1.1048, 1.1059, 1.1069,
1.1077, 1.1085, 1.1097, 1.1113, 1.1134, 1.1157, 1.1179, 1.1198,
1.1217, 1.1235, 1.1255, 1.1265, 1.1278, 1.1293, 1.1307, 1.1309,
1.1307, 1.1307, 1.1311, 1.1318, 1.1324, 1.133, 1.1332, 1.1336,
1.1336, 1.1335, 1.1334, 1.1337, 1.1344, 1.135, 1.1354, 1.1355,
1.1356, 1.1354, 1.1354, 1.1361, 1.1367, 1.1368, 1.1368, 1.1366,
1.1362, 1.1358, 1.1358, 1.1356, 1.1348, 1.1339, 1.1332, 1.1315,
1.1295, 1.1277, 1.1262, 1.1249, 1.1247, 1.1246, 1.1245, 1.1244,
1.1241, 1.1238, 1.1236, 1.1231, 1.1233, 1.1234, 1.1237, 1.1242,
1.1247, 1.1254, 1.1263, 1.1263, 1.1258, 1.1254, 1.1251, 1.1249,
1.1237, 1.1227, 1.1213, 1.1198, 1.1186, 1.1176, 1.1164, 1.1157,
1.1148, 1.1143, 1.1131, 1.1119, 1.1108, 1.1094, 1.1076, 1.1069,
1.1067, 1.1064, 1.106, 1.1059, 1.1061, 1.1061, 1.1068, 1.1071,
1.1074, 1.1076, 1.1078, 1.108, 1.1085, 1.1085, 1.1092, 1.1097,
1.111, 1.1124, 1.114, 1.1158, 1.1174, 1.119, 1.12, 1.1211, 1.1212,
1.1213, 1.1209, 1.1209, 1.1213, 1.1216, 1.1219, 1.1226, 1.1229,
1.1235, 1.1239, 1.1242, 1.1239, 1.1237, 1.1231, 1.1223, 1.1215,
1.1208, 1.1204, 1.12, 1.1202, 1.1205, 1.1208, 1.1211, 1.1213,
1.1217, 1.122, 1.1217, 1.1215, 1.121, 1.1208, 1.1204, 1.1195,
1.1183, 1.1174, 1.1165, 1.1156, 1.1147, 1.1137, 1.1123, 1.1106,
1.1087, 1.1071, 1.1055, 1.1039, 1.1026, 1.1015, 1.1008, 1.1002,
1.1, 1.0997, 1.0992, 1.0991, 1.0986, 1.0978, 1.0972, 1.0959,
1.0946, 1.0931, 1.0916, 1.0902, 1.0889, 1.0876, 1.0858, 1.0841,
1.0821, 1.0803, 1.0783, 1.0757, 1.0735, 1.0711, 1.0697, 1.0682,
1.0674, 1.066, 1.0645, 1.064, 1.0635, 1.0628, 1.0617, 1.061,
1.0599, 1.0587, 1.058, 1.0575, 1.0568, 1.056, 1.055, 1.0542,
1.0533, 1.0526, 1.051, 1.0495, 1.0481, 1.0481, 1.0479, 1.0476,
1.0473, 1.0475, 1.0485, 1.0495, 1.0505, 1.0521, 1.0531, 1.0543,
1.0555, 1.057, 1.0584, 1.0601, 1.061, 1.062, 1.0632, 1.0651,
1.0665, 1.0673, 1.0685, 1.0694, 1.0701, 1.0706, 1.0708, 1.0708,
1.0708, 1.0702, 1.07, 1.0701, 1.0696, 1.0689, 1.0679, 1.0669,
1.0664, 1.3465, 1.3455, 1.3446, 1.3436, 1.3427, 1.3413, 1.3399,
1.3383, 1.3368, 1.3354, 1.334, 1.3327, 1.3314, 1.3301, 1.3285,
1.3272, 1.3256, 1.3241, 1.3226, 1.3211, 1.3196, 1.3179, 1.3162,
1.3146, 1.3129, 1.3113, 1.3095, 1.3079, 1.3064, 1.3051, 1.3037,
1.3021, 1.3007, 1.2993, 1.2982, 1.2971, 1.2958, 1.2946, 1.2933,
1.2919, 1.2905, 1.289, 1.2877, 1.2865, 1.2853, 1.2839, 1.2825,
1.2811, 1.2798, 1.2784, 1.2768, 1.2754, 1.274, 1.2727, 1.2713,
1.2703, 1.2695, 1.2686, 1.2678, 1.2671, 1.2663, 1.2652, 1.2642,
1.2632, 1.2625, 1.2616, 1.2608, 1.2601, 1.2591, 1.2582, 1.2574,
1.2566, 1.2559, 1.2554, 1.255, 1.2545, 1.2544, 1.254, 1.2537,
1.2529, 1.2521, 1.2513, 1.2502, 1.2493, 1.248, 1.2468, 1.2456,
1.2444, 1.2432, 1.2421, 1.241, 1.2397, 1.2382, 1.2365, 1.2349,
1.2333, 1.2319, 1.2306, 1.2291, 1.2277, 1.2262, 1.2244, 1.2228,
1.2209, 1.2193, 1.217, 1.2144, 1.212, 1.2097, 1.2071, 1.2047,
1.2025, 1.2003, 1.1983, 1.196, 1.194, 1.1917, 1.1894, 1.1873,
1.1854, 1.1834, 1.1816, 1.1797, 1.1778, 1.1757, 1.1736, 1.1714,
1.1692, 1.1669, 1.1649, 1.1628, 1.1607, 1.1586, 1.1566, 1.1544,
1.152, 1.1493, 1.1467, 1.1438, 1.1407, 1.1377, 1.1347, 1.132,
1.1294, 1.1275, 1.1252, 1.1232, 1.1214, 1.1197, 1.118, 1.1166,
1.1152, 1.1136, 1.112, 1.1103, 1.1093, 1.1089, 1.1082, 1.1071,
1.1061, 1.1048, 1.1034, 1.1019, 1.1002, 1.0989, 1.0974, 1.0964,
1.0953, 1.0941, 1.0929, 1.0917, 1.0907, 1.0897, 1.0889, 1.0883,
1.088, 1.0877, 1.0873, 1.087, 1.087, 1.0871, 1.0871, 1.0871,
1.0871, 1.0877, 1.0884, 1.0897, 1.0906, 1.0915, 1.0926, 1.0935,
1.0946, 1.0954, 1.0959, 1.096, 1.0966, 1.0969, 1.0969, 1.0973,
1.098, 1.0987, 1.0991, 1.1, 1.1011, 1.1023, 1.103, 1.1036, 1.1043,
1.1052, 1.1063, 1.1077, 1.1092, 1.1107, 1.1118, 1.1128, 1.1137,
1.1144, 1.1154, 1.1162, 1.1169, 1.1174, 1.1179, 1.1182, 1.1183,
1.1182, 1.1178, 1.1177, 1.1174, 1.1171, 1.1163, 1.1155, 1.1148,
1.1141, 1.1136, 1.1127, 1.1119, 1.1109, 1.1105, 1.1103, 1.1101,
1.1097, 1.1097, 1.1096, 1.1096, 1.1096, 1.1096, 1.1095, 1.1097,
1.1095, 1.1093, 1.1091, 1.1091, 1.1087, 1.1081, 1.1077, 1.1077,
1.1079, 1.1086, 1.1091, 1.1091, 1.1089, 1.1085, 1.1083, 1.1086,
1.1086, 1.1085, 1.1084, 1.1083, 1.1084, 1.1087, 1.1091, 1.1096,
1.1101, 1.1106, 1.111, 1.1118, 1.1121, 1.1125, 1.1127, 1.1132,
1.1139, 1.1146, 1.1154, 1.1161, 1.1166, 1.117, 1.1174, 1.1176,
1.1181, 1.1186, 1.1193, 1.12, 1.1208, 1.1218, 1.123, 1.1239,
1.1246, 1.1253, 1.1259, 1.1262, 1.1261, 1.126, 1.1259, 1.126,
1.1256, 1.1251, 1.1243, 1.1231, 1.122, 1.1211, 1.1204, 1.1195,
1.1186, 1.1174, 1.1164, 1.1158, 1.115, 1.1141, 1.1129, 1.1118,
1.1108, 1.1094, 1.108, 1.1068, 1.1054, 1.1038, 1.1024, 1.1011,
1.1001, 1.099, 1.0984, 1.0978, 1.097, 1.0963, 1.096, 1.0955,
1.095, 1.0946, 1.0939, 1.0933, 1.0924, 1.0914, 1.0905, 1.0897,
1.0885, 1.0877, 1.0869, 1.0862, 1.0853, 1.0845, 1.084, 1.0837,
1.0833, 1.0827, 1.0824, 1.0823, 1.0821, 1.0818, 1.0816, 1.0816,
1.0816, 1.0819, 1.0822, 1.0826, 1.0829, 1.083, 1.083, 1.0834,
1.0838, 1.0843, 1.0847, 1.0851, 1.0856, 1.0861, 1.0871, 1.0883,
1.0894, 1.0907, 1.092, 1.0933, 1.0941, 1.0948, 1.0955, 1.096,
1.0962, 1.0965, 1.0968, 1.0969, 1.0971, 1.0973, 1.0977, 1.0978,
1.0977, 1.0975, 1.0974, 1.0974, 1.0975, 1.0976, 1.0978, 1.0979,
1.0986, 1.0992, 1.0997, 1.1004, 1.1013, 1.1021, 1.1028, 1.1035,
1.1043, 1.1049, 1.1055, 1.106, 1.1066, 1.1074, 1.1083, 1.1093,
1.1105, 1.1115, 1.1126, 1.1136, 1.1145, 1.1156, 1.1166, 1.1176,
1.1179, 1.118, 1.1183, 1.1185, 1.1186, 1.1187, 1.1186, 1.1185,
1.1187, 1.119, 1.1194, 1.1199, 1.1206, 1.1216, 1.1225, 1.1235,
1.1242, 1.1252, 1.1262, 1.1272, 1.1283, 1.1292, 1.1298, 1.1304,
1.131, 1.1314, 1.1315, 1.1316, 1.1319, 1.1319, 1.1318, 1.1315,
1.1312, 1.131, 1.1308, 1.1309, 1.1308, 1.1312, 1.1315, 1.1317,
1.1318, 1.1317, 1.1314, 1.1312, 1.1308, 1.1305, 1.1302, 1.13,
1.1298, 1.1295, 1.1296, 1.1298, 1.1295, 1.1289, 1.1283, 1.128,
1.1276, 1.1274, 1.1272, 1.1267, 1.1263, 1.1257, 1.1249, 1.124,
1.1231, 1.1223, 1.1217, 1.121, 1.1204, 1.1197, 1.1189, 1.1182,
1.1175, 1.1168, 1.1162, 1.1159, 1.1156, 1.1155, 1.1154, 1.1156,
1.1156, 1.1154, 1.1154, 1.1153, 1.1152, 1.1152, 1.1152, 1.1148,
1.1144, 1.1143, 1.1141, 1.1141, 1.1143, 1.1144, 1.1145, 1.1146,
1.1147, 1.1145, 1.1143, 1.1141, 1.1138, 1.1134, 1.1135, 1.1137,
1.1141, 1.1143, 1.1147, 1.1148, 1.115, 1.1153, 1.1156, 1.116,
1.1162, 1.1164, 1.1166, 1.1168, 1.117, 1.1173, 1.1177, 1.1181,
1.1185, 1.1189, 1.1194, 1.1198, 1.1203, 1.1206, 1.1207, 1.1208,
1.1207, 1.1204, 1.1201, 1.1199, 1.1197, 1.1195, 1.1193, 1.1189,
1.1184, 1.1179, 1.1173, 1.1165, 1.1157, 1.1148, 1.1141, 1.1135,
1.113, 1.1126, 1.1123, 1.1122, 1.1119, 1.1116, 1.1111, 1.1105,
1.1099, 1.1091, 1.108, 1.1069, 1.1057, 1.1044, 1.1032, 1.102,
1.1006, 1.0992, 1.0981, 1.097, 1.096, 1.0948, 1.0937, 1.0925,
1.0916, 1.0906, 1.0896, 1.0884, 1.0871, 1.0859, 1.0848, 1.0834,
1.082, 1.0805, 1.079, 1.0777, 1.0765, 1.0753, 1.0742, 1.0731,
1.0721, 1.071, 1.0701, 1.0693, 1.0685, 1.0675, 1.0667, 1.0661,
1.0652, 1.0644, 1.0634, 1.0624, 1.0614, 1.0604, 1.0595, 1.0589,
1.0583, 1.0578, 1.0575, 1.0576, 1.0576, 1.0577, 1.0578, 1.0581,
1.0582, 1.0585, 1.059, 1.0594, 1.0598, 1.06, 1.0601, 1.0603,
1.0603, 1.0603, 1.0599, 1.0597, 1.0594, 1.0595, 1.0596, 1.0595,
1.0594, 1.0594, 1.0597), index = structure(c(1409202000, 1409288400,
1409547600, 1409634000, 1409720400, 1409806800, 1409893200, 1410152400,
1410238800, 1410325200, 1410411600, 1410498000, 1410757200, 1410843600,
1410930000, 1411016400, 1411102800, 1411362000, 1411448400, 1411534800,
1411621200, 1411707600, 1411966800, 1412053200, 1412139600, 1412226000,
1412312400, 1412571600, 1412658000, 1412744400, 1412830800, 1412917200,
1413176400, 1413262800, 1413349200, 1413435600, 1413522000, 1413781200,
1413867600, 1413954000, 1414040400, 1414126800, 1414386000, 1414472400,
1414558800, 1414645200, 1414731600, 1414994400, 1415080800, 1415167200,
1415253600, 1415340000, 1415599200, 1415685600, 1415772000, 1415858400,
1415944800, 1416204000, 1416290400, 1416376800, 1416463200, 1416549600,
1416808800, 1416895200, 1416981600, 1417068000, 1417154400, 1417413600,
1417500000, 1417586400, 1417672800, 1417759200, 1418018400, 1418104800,
1418191200, 1418277600, 1418364000, 1418623200, 1418709600, 1418796000,
1418882400, 1418968800, 1419228000, 1419314400, 1419400800, 1419487200,
1419573600, 1419832800, 1419919200, 1420005600, 1420092000, 1420178400,
1420437600, 1420524000, 1420610400, 1420696800, 1420783200, 1421042400,
1421128800, 1421215200, 1421301600, 1421388000, 1421647200, 1421733600,
1421820000, 1421906400, 1421992800, 1422252000, 1422338400, 1422424800,
1422511200, 1422597600, 1422856800, 1422943200, 1423029600, 1423116000,
1423202400, 1423461600, 1423548000, 1423634400, 1423720800, 1423807200,
1424066400, 1424152800, 1424239200, 1424325600, 1424412000, 1424671200,
1424757600, 1424844000, 1424930400, 1425016800, 1425276000, 1425362400,
1425448800, 1425535200, 1425621600, 1425877200, 1425963600, 1426050000,
1426136400, 1426222800, 1426482000, 1426568400, 1426654800, 1426741200,
1426827600, 1427086800, 1427173200, 1427259600, 1427346000, 1427432400,
1427691600, 1427778000, 1427864400, 1427950800, 1428037200, 1428296400,
1428382800, 1428469200, 1428555600, 1428642000, 1428901200, 1428987600,
1429074000, 1429160400, 1429246800, 1429506000, 1429592400, 1429678800,
1429765200, 1429851600, 1430110800, 1430197200, 1430283600, 1430370000,
1430456400, 1430715600, 1430802000, 1430888400, 1430974800, 1431061200,
1431320400, 1431406800, 1431493200, 1431579600, 1431666000, 1431925200,
1432011600, 1432098000, 1432184400, 1432270800, 1432530000, 1432616400,
1432702800, 1432789200, 1432875600, 1433134800, 1433221200, 1433307600,
1433394000, 1433480400, 1433739600, 1433826000, 1433912400, 1433998800,
1434085200, 1434344400, 1434430800, 1434517200, 1434603600, 1434690000,
1434949200, 1435035600, 1435122000, 1435208400, 1435294800, 1435554000,
1435640400, 1435726800, 1435813200, 1435899600, 1436158800, 1436245200,
1436331600, 1436418000, 1436504400, 1436763600, 1436850000, 1436936400,
1437022800, 1437109200, 1437368400, 1437454800, 1437541200, 1437627600,
1437714000, 1437973200, 1438059600, 1438146000, 1438232400, 1438318800,
1438578000, 1438664400, 1438750800, 1438837200, 1438923600, 1439182800,
1439269200, 1439355600, 1439442000, 1439528400, 1439787600, 1439874000,
1439960400, 1440046800, 1440133200, 1440392400, 1440478800, 1440565200,
1440651600, 1440738000, 1440997200, 1441083600, 1441170000, 1441256400,
1441342800, 1441602000, 1441688400, 1441774800, 1441861200, 1441947600,
1442206800, 1442293200, 1442379600, 1442466000, 1442552400, 1442811600,
1442898000, 1442984400, 1443070800, 1443157200, 1443416400, 1443502800,
1443589200, 1443675600, 1443762000, 1444021200, 1444107600, 1444194000,
1444280400, 1444366800, 1444626000, 1444712400, 1444798800, 1444885200,
1444971600, 1445230800, 1445317200, 1445403600, 1445490000, 1445576400,
1445835600, 1445922000, 1446008400, 1446094800, 1446181200, 1446444000,
1446530400, 1446616800, 1446703200, 1446789600, 1447048800, 1447135200,
1447221600, 1447308000, 1447394400, 1447653600, 1447740000, 1447826400,
1447912800, 1447999200, 1448258400, 1448344800, 1448431200, 1448517600,
1448604000, 1448863200, 1448949600, 1449036000, 1449122400, 1449208800,
1449468000, 1449554400, 1449640800, 1449727200, 1449813600, 1450072800,
1450159200, 1450245600, 1450332000, 1450418400, 1450677600, 1450764000,
1450850400, 1450936800, 1451023200, 1451282400, 1451368800, 1451455200,
1451541600, 1451628000, 1451887200, 1451973600, 1452060000, 1452146400,
1452232800, 1452492000, 1452578400, 1452664800, 1452751200, 1452837600,
1453096800, 1453183200, 1453269600, 1453356000, 1453442400, 1453701600,
1453788000, 1453874400, 1453960800, 1454047200, 1454306400, 1454392800,
1454479200, 1454565600, 1454652000, 1454911200, 1454997600, 1455084000,
1455170400, 1455256800, 1455516000, 1455602400, 1455688800, 1455775200,
1455861600, 1456120800, 1456207200, 1456293600, 1456380000, 1456466400,
1456725600, 1456812000, 1456898400, 1456984800, 1457071200, 1457330400,
1457416800, 1457503200, 1457589600, 1457676000, 1457931600, 1458018000,
1458104400, 1458190800, 1458277200, 1458536400, 1458622800, 1458709200,
1458795600, 1458882000, 1459141200, 1459227600, 1459314000, 1459400400,
1459486800, 1459746000, 1459832400, 1459918800, 1460005200, 1460091600,
1460350800, 1460437200, 1460523600, 1460610000, 1460696400, 1460955600,
1461042000, 1461128400, 1461214800, 1461301200, 1461560400, 1461646800,
1461733200, 1461819600, 1461906000, 1462165200, 1462251600, 1462338000,
1462424400, 1462510800, 1462770000, 1462856400, 1462942800, 1463029200,
1463115600, 1463374800, 1463461200, 1463547600, 1463634000, 1463720400,
1463979600, 1464066000, 1464152400, 1464238800, 1464325200, 1464584400,
1464670800, 1464757200, 1464843600, 1464930000, 1465189200, 1465275600,
1465362000, 1465448400, 1465534800, 1465794000, 1465880400, 1465966800,
1466053200, 1466139600, 1466398800, 1466485200, 1466571600, 1466658000,
1466744400, 1467003600, 1467090000, 1467176400, 1467262800, 1467349200,
1467608400, 1467694800, 1467781200, 1467867600, 1467954000, 1468213200,
1468299600, 1468386000, 1468472400, 1468558800, 1468818000, 1468904400,
1468990800, 1469077200, 1469163600, 1469422800, 1469509200, 1469595600,
1469682000, 1469768400, 1470027600, 1470114000, 1470200400, 1470286800,
1470373200, 1470632400, 1470718800, 1470805200, 1470891600, 1470978000,
1471237200, 1471323600, 1471410000, 1471496400, 1471582800, 1471842000,
1471928400, 1472014800, 1472101200, 1472187600, 1472446800, 1472533200,
1472619600, 1472706000, 1472792400, 1473051600, 1473138000, 1473224400,
1473310800, 1473397200, 1473656400, 1473742800, 1473829200, 1473915600,
1474002000, 1474261200, 1474347600, 1474434000, 1474520400, 1474606800,
1474866000, 1474952400, 1475038800, 1475125200, 1475211600, 1475470800,
1475557200, 1475643600, 1475730000, 1475816400, 1476075600, 1476162000,
1476248400, 1476334800, 1476421200, 1476680400, 1476766800, 1476853200,
1476939600, 1477026000, 1477285200, 1477371600, 1477458000, 1477544400,
1477630800, 1477890000, 1477976400, 1478062800, 1478149200, 1478235600,
1478498400, 1478584800, 1478671200, 1478757600, 1478844000, 1479103200,
1479189600, 1479276000, 1479362400, 1479448800, 1479708000, 1479794400,
1479880800, 1479967200, 1480053600, 1480312800, 1480399200, 1480485600,
1480572000, 1480658400, 1480917600, 1481004000, 1481090400, 1481176800,
1481263200, 1481522400, 1481608800, 1481695200, 1481781600, 1481868000,
1482127200, 1482213600, 1482300000, 1482386400, 1482472800, 1482732000,
1482818400, 1482904800, 1482991200, 1483077600, 1483336800, 1483423200,
1483509600, 1483596000, 1483682400, 1483941600, 1484028000, 1484114400,
1484200800, 1484287200, 1484546400, 1484632800, 1484719200, 1484805600,
1484892000, 1485151200, 1485237600, 1485324000, 1485410400, 1485496800,
1485756000, 1485842400, 1485928800, 1486015200, 1486101600, 1486360800,
1486447200, 1486533600, 1486620000, 1486706400, 1486965600, 1487052000,
1487138400, 1487224800, 1487311200, 1487570400, 1487656800, 1487743200,
1487829600), tzone = "", tclass = c("POSIXct", "POSIXt")), .indexCLASS = c("POSIXct",
"POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "", class = c("xts",
"zoo"), .Dim = c(651L, 2L), .Dimnames = list(NULL, c("EUR.20D",
"EUR.50D")))
不,有 10 个交叉点。您可以使用 diff
、sign
和 which
:
观察到这一点
df1[which(diff(sign(df1[,1]-df1[,2]))!=0),]
EUR.20D EUR.50D
2015-05-06 01:00:00 1.0887 1.0870
2015-07-13 01:00:00 1.1168 1.1174
2015-08-25 01:00:00 1.1100 1.1091
2015-10-27 01:00:00 1.1256 1.1260
2015-12-25 01:00:00 1.0878 1.0869
2016-05-30 01:00:00 1.1295 1.1310
2016-08-19 01:00:00 1.1158 1.1143
2016-10-07 01:00:00 1.1208 1.1208
2016-10-10 01:00:00 1.1204 1.1207
2017-01-24 01:00:00 1.0584 1.0576
如果这不是正确的话题,我深表歉意。我只是对 R 中的以下问题感到非常困惑。我正在尝试为移动平均线交叉设置信号(20 天 MA 和 50 天 MA)。换句话说,我试图创建一个向量列表,当绿线越过紫色线时为 1,对于其他情况(紫色超过绿色)为 -1,否则为 0。
我的情节中似乎有大约 8 个交叉点,但是当我尝试使用 which
作为完整性检查时:
which(data[,5]==data[,6])
其中 data[5] 是绿线,而 data[6] 是紫色,我只返回第 551 行。因此,(我假设)我尝试使用的这条线没有工作:
signal <- ifelse((data[,5]==data[,6])&(data[,5]>data[,6]), 1, ifelse((data[,5]==data[,6])&(data[,5]<data[,6]), -1, 0)
非常感谢您的帮助!下面附上我的样本输出:
structure(c(1.3323, 1.3309, 1.3294, 1.3282, 1.327, 1.3249, 1.3226,
1.3202, 1.318, 1.3158, 1.3136, 1.3114, 1.3093, 1.3075, 1.3055,
1.3037, 1.3016, 1.2999, 1.2983, 1.2963, 1.2941, 1.2919, 1.2896,
1.2871, 1.2845, 1.2831, 1.2809, 1.2797, 1.2784, 1.2775, 1.2763,
1.2746, 1.2737, 1.2722, 1.2721, 1.2715, 1.2712, 1.2709, 1.2703,
1.2696, 1.2691, 1.269, 1.2691, 1.2696, 1.2696, 1.2694, 1.2694,
1.2685, 1.2679, 1.2667, 1.2651, 1.2642, 1.2626, 1.2617, 1.2597,
1.258, 1.2568, 1.2551, 1.2542, 1.2537, 1.2532, 1.2518, 1.2505,
1.2492, 1.2486, 1.2478, 1.2475, 1.2474, 1.2466, 1.2457, 1.2457,
1.2449, 1.2443, 1.2438, 1.2439, 1.2436, 1.2432, 1.2432, 1.2431,
1.242, 1.2407, 1.2399, 1.2389, 1.2374, 1.2358, 1.2346, 1.2332,
1.2317, 1.2305, 1.2295, 1.2281, 1.2267, 1.2248, 1.2223, 1.2193,
1.2162, 1.2131, 1.2101, 1.2064, 1.2036, 1.2004, 1.1971, 1.1939,
1.1908, 1.1879, 1.1836, 1.1787, 1.1741, 1.1703, 1.1662, 1.1623,
1.1587, 1.1558, 1.1537, 1.1513, 1.1497, 1.147, 1.1445, 1.1422,
1.14, 1.1388, 1.138, 1.1367, 1.136, 1.1349, 1.135, 1.1358, 1.1363,
1.1361, 1.1365, 1.1359, 1.1354, 1.1346, 1.1331, 1.1318, 1.1295,
1.1272, 1.1248, 1.1217, 1.1177, 1.1139, 1.1094, 1.1055, 1.1014,
1.0987, 1.0952, 1.0924, 1.0905, 1.0884, 1.0864, 1.0849, 1.0833,
1.0816, 1.0793, 1.0778, 1.077, 1.0776, 1.078, 1.0786, 1.0797,
1.0799, 1.0804, 1.0804, 1.0807, 1.0798, 1.0803, 1.0802, 1.0792,
1.0782, 1.077, 1.0767, 1.0766, 1.0769, 1.0782, 1.08, 1.0817,
1.0829, 1.084, 1.0858, 1.0887, 1.0917, 1.0947, 1.0976, 1.1004,
1.1038, 1.107, 1.1102, 1.1131, 1.1152, 1.117, 1.1185, 1.1192,
1.1196, 1.1191, 1.1179, 1.1166, 1.1155, 1.1144, 1.1142, 1.1139,
1.1137, 1.1133, 1.114, 1.1143, 1.1142, 1.1134, 1.1125, 1.1123,
1.1128, 1.1141, 1.1153, 1.117, 1.1188, 1.1203, 1.1218, 1.1231,
1.124, 1.1255, 1.1255, 1.1244, 1.1236, 1.1236, 1.1224, 1.1211,
1.1198, 1.1187, 1.1182, 1.1168, 1.1156, 1.1137, 1.1112, 1.1086,
1.1061, 1.1049, 1.1035, 1.1024, 1.1015, 1.1008, 1.1003, 1.1,
1.0992, 1.0986, 1.098, 1.0974, 1.0965, 1.096, 1.095, 1.0951,
1.0953, 1.0963, 1.0977, 1.0991, 1.1003, 1.1008, 1.1017, 1.103,
1.105, 1.1077, 1.11, 1.1116, 1.1132, 1.1142, 1.1155, 1.1177,
1.1193, 1.1203, 1.1212, 1.1219, 1.1227, 1.123, 1.1236, 1.1248,
1.126, 1.1272, 1.128, 1.129, 1.1286, 1.1264, 1.1244, 1.1238,
1.1237, 1.1238, 1.1239, 1.1236, 1.1234, 1.1237, 1.124, 1.1241,
1.1245, 1.1246, 1.1246, 1.1247, 1.1249, 1.1255, 1.1264, 1.1261,
1.1264, 1.1271, 1.1282, 1.129, 1.1284, 1.1275, 1.1266, 1.1256,
1.1243, 1.1232, 1.1222, 1.1213, 1.1198, 1.1179, 1.1159, 1.1129,
1.1098, 1.1065, 1.1029, 1.1, 1.0972, 1.094, 1.0904, 1.087, 1.0852,
1.0833, 1.0812, 1.0792, 1.0777, 1.0758, 1.0738, 1.0715, 1.0698,
1.0686, 1.0689, 1.0696, 1.07, 1.0708, 1.0722, 1.0729, 1.0739,
1.0755, 1.0769, 1.0782, 1.0786, 1.0798, 1.0811, 1.0827, 1.0842,
1.0859, 1.0878, 1.0898, 1.0912, 1.0928, 1.0924, 1.0923, 1.0923,
1.0915, 1.0903, 1.0903, 1.0899, 1.0893, 1.0889, 1.0887, 1.0889,
1.0892, 1.0891, 1.0888, 1.0887, 1.0883, 1.0874, 1.0868, 1.0866,
1.0864, 1.0868, 1.0867, 1.0869, 1.0878, 1.0894, 1.0908, 1.092,
1.0937, 1.0958, 1.0979, 1.1002, 1.1019, 1.1032, 1.1044, 1.1056,
1.1068, 1.1084, 1.1093, 1.1101, 1.1107, 1.1111, 1.1116, 1.1115,
1.1113, 1.1101, 1.1088, 1.108, 1.1071, 1.1057, 1.1043, 1.1035,
1.103, 1.1028, 1.1026, 1.1031, 1.1041, 1.1048, 1.1059, 1.1069,
1.1077, 1.1085, 1.1097, 1.1113, 1.1134, 1.1157, 1.1179, 1.1198,
1.1217, 1.1235, 1.1255, 1.1265, 1.1278, 1.1293, 1.1307, 1.1309,
1.1307, 1.1307, 1.1311, 1.1318, 1.1324, 1.133, 1.1332, 1.1336,
1.1336, 1.1335, 1.1334, 1.1337, 1.1344, 1.135, 1.1354, 1.1355,
1.1356, 1.1354, 1.1354, 1.1361, 1.1367, 1.1368, 1.1368, 1.1366,
1.1362, 1.1358, 1.1358, 1.1356, 1.1348, 1.1339, 1.1332, 1.1315,
1.1295, 1.1277, 1.1262, 1.1249, 1.1247, 1.1246, 1.1245, 1.1244,
1.1241, 1.1238, 1.1236, 1.1231, 1.1233, 1.1234, 1.1237, 1.1242,
1.1247, 1.1254, 1.1263, 1.1263, 1.1258, 1.1254, 1.1251, 1.1249,
1.1237, 1.1227, 1.1213, 1.1198, 1.1186, 1.1176, 1.1164, 1.1157,
1.1148, 1.1143, 1.1131, 1.1119, 1.1108, 1.1094, 1.1076, 1.1069,
1.1067, 1.1064, 1.106, 1.1059, 1.1061, 1.1061, 1.1068, 1.1071,
1.1074, 1.1076, 1.1078, 1.108, 1.1085, 1.1085, 1.1092, 1.1097,
1.111, 1.1124, 1.114, 1.1158, 1.1174, 1.119, 1.12, 1.1211, 1.1212,
1.1213, 1.1209, 1.1209, 1.1213, 1.1216, 1.1219, 1.1226, 1.1229,
1.1235, 1.1239, 1.1242, 1.1239, 1.1237, 1.1231, 1.1223, 1.1215,
1.1208, 1.1204, 1.12, 1.1202, 1.1205, 1.1208, 1.1211, 1.1213,
1.1217, 1.122, 1.1217, 1.1215, 1.121, 1.1208, 1.1204, 1.1195,
1.1183, 1.1174, 1.1165, 1.1156, 1.1147, 1.1137, 1.1123, 1.1106,
1.1087, 1.1071, 1.1055, 1.1039, 1.1026, 1.1015, 1.1008, 1.1002,
1.1, 1.0997, 1.0992, 1.0991, 1.0986, 1.0978, 1.0972, 1.0959,
1.0946, 1.0931, 1.0916, 1.0902, 1.0889, 1.0876, 1.0858, 1.0841,
1.0821, 1.0803, 1.0783, 1.0757, 1.0735, 1.0711, 1.0697, 1.0682,
1.0674, 1.066, 1.0645, 1.064, 1.0635, 1.0628, 1.0617, 1.061,
1.0599, 1.0587, 1.058, 1.0575, 1.0568, 1.056, 1.055, 1.0542,
1.0533, 1.0526, 1.051, 1.0495, 1.0481, 1.0481, 1.0479, 1.0476,
1.0473, 1.0475, 1.0485, 1.0495, 1.0505, 1.0521, 1.0531, 1.0543,
1.0555, 1.057, 1.0584, 1.0601, 1.061, 1.062, 1.0632, 1.0651,
1.0665, 1.0673, 1.0685, 1.0694, 1.0701, 1.0706, 1.0708, 1.0708,
1.0708, 1.0702, 1.07, 1.0701, 1.0696, 1.0689, 1.0679, 1.0669,
1.0664, 1.3465, 1.3455, 1.3446, 1.3436, 1.3427, 1.3413, 1.3399,
1.3383, 1.3368, 1.3354, 1.334, 1.3327, 1.3314, 1.3301, 1.3285,
1.3272, 1.3256, 1.3241, 1.3226, 1.3211, 1.3196, 1.3179, 1.3162,
1.3146, 1.3129, 1.3113, 1.3095, 1.3079, 1.3064, 1.3051, 1.3037,
1.3021, 1.3007, 1.2993, 1.2982, 1.2971, 1.2958, 1.2946, 1.2933,
1.2919, 1.2905, 1.289, 1.2877, 1.2865, 1.2853, 1.2839, 1.2825,
1.2811, 1.2798, 1.2784, 1.2768, 1.2754, 1.274, 1.2727, 1.2713,
1.2703, 1.2695, 1.2686, 1.2678, 1.2671, 1.2663, 1.2652, 1.2642,
1.2632, 1.2625, 1.2616, 1.2608, 1.2601, 1.2591, 1.2582, 1.2574,
1.2566, 1.2559, 1.2554, 1.255, 1.2545, 1.2544, 1.254, 1.2537,
1.2529, 1.2521, 1.2513, 1.2502, 1.2493, 1.248, 1.2468, 1.2456,
1.2444, 1.2432, 1.2421, 1.241, 1.2397, 1.2382, 1.2365, 1.2349,
1.2333, 1.2319, 1.2306, 1.2291, 1.2277, 1.2262, 1.2244, 1.2228,
1.2209, 1.2193, 1.217, 1.2144, 1.212, 1.2097, 1.2071, 1.2047,
1.2025, 1.2003, 1.1983, 1.196, 1.194, 1.1917, 1.1894, 1.1873,
1.1854, 1.1834, 1.1816, 1.1797, 1.1778, 1.1757, 1.1736, 1.1714,
1.1692, 1.1669, 1.1649, 1.1628, 1.1607, 1.1586, 1.1566, 1.1544,
1.152, 1.1493, 1.1467, 1.1438, 1.1407, 1.1377, 1.1347, 1.132,
1.1294, 1.1275, 1.1252, 1.1232, 1.1214, 1.1197, 1.118, 1.1166,
1.1152, 1.1136, 1.112, 1.1103, 1.1093, 1.1089, 1.1082, 1.1071,
1.1061, 1.1048, 1.1034, 1.1019, 1.1002, 1.0989, 1.0974, 1.0964,
1.0953, 1.0941, 1.0929, 1.0917, 1.0907, 1.0897, 1.0889, 1.0883,
1.088, 1.0877, 1.0873, 1.087, 1.087, 1.0871, 1.0871, 1.0871,
1.0871, 1.0877, 1.0884, 1.0897, 1.0906, 1.0915, 1.0926, 1.0935,
1.0946, 1.0954, 1.0959, 1.096, 1.0966, 1.0969, 1.0969, 1.0973,
1.098, 1.0987, 1.0991, 1.1, 1.1011, 1.1023, 1.103, 1.1036, 1.1043,
1.1052, 1.1063, 1.1077, 1.1092, 1.1107, 1.1118, 1.1128, 1.1137,
1.1144, 1.1154, 1.1162, 1.1169, 1.1174, 1.1179, 1.1182, 1.1183,
1.1182, 1.1178, 1.1177, 1.1174, 1.1171, 1.1163, 1.1155, 1.1148,
1.1141, 1.1136, 1.1127, 1.1119, 1.1109, 1.1105, 1.1103, 1.1101,
1.1097, 1.1097, 1.1096, 1.1096, 1.1096, 1.1096, 1.1095, 1.1097,
1.1095, 1.1093, 1.1091, 1.1091, 1.1087, 1.1081, 1.1077, 1.1077,
1.1079, 1.1086, 1.1091, 1.1091, 1.1089, 1.1085, 1.1083, 1.1086,
1.1086, 1.1085, 1.1084, 1.1083, 1.1084, 1.1087, 1.1091, 1.1096,
1.1101, 1.1106, 1.111, 1.1118, 1.1121, 1.1125, 1.1127, 1.1132,
1.1139, 1.1146, 1.1154, 1.1161, 1.1166, 1.117, 1.1174, 1.1176,
1.1181, 1.1186, 1.1193, 1.12, 1.1208, 1.1218, 1.123, 1.1239,
1.1246, 1.1253, 1.1259, 1.1262, 1.1261, 1.126, 1.1259, 1.126,
1.1256, 1.1251, 1.1243, 1.1231, 1.122, 1.1211, 1.1204, 1.1195,
1.1186, 1.1174, 1.1164, 1.1158, 1.115, 1.1141, 1.1129, 1.1118,
1.1108, 1.1094, 1.108, 1.1068, 1.1054, 1.1038, 1.1024, 1.1011,
1.1001, 1.099, 1.0984, 1.0978, 1.097, 1.0963, 1.096, 1.0955,
1.095, 1.0946, 1.0939, 1.0933, 1.0924, 1.0914, 1.0905, 1.0897,
1.0885, 1.0877, 1.0869, 1.0862, 1.0853, 1.0845, 1.084, 1.0837,
1.0833, 1.0827, 1.0824, 1.0823, 1.0821, 1.0818, 1.0816, 1.0816,
1.0816, 1.0819, 1.0822, 1.0826, 1.0829, 1.083, 1.083, 1.0834,
1.0838, 1.0843, 1.0847, 1.0851, 1.0856, 1.0861, 1.0871, 1.0883,
1.0894, 1.0907, 1.092, 1.0933, 1.0941, 1.0948, 1.0955, 1.096,
1.0962, 1.0965, 1.0968, 1.0969, 1.0971, 1.0973, 1.0977, 1.0978,
1.0977, 1.0975, 1.0974, 1.0974, 1.0975, 1.0976, 1.0978, 1.0979,
1.0986, 1.0992, 1.0997, 1.1004, 1.1013, 1.1021, 1.1028, 1.1035,
1.1043, 1.1049, 1.1055, 1.106, 1.1066, 1.1074, 1.1083, 1.1093,
1.1105, 1.1115, 1.1126, 1.1136, 1.1145, 1.1156, 1.1166, 1.1176,
1.1179, 1.118, 1.1183, 1.1185, 1.1186, 1.1187, 1.1186, 1.1185,
1.1187, 1.119, 1.1194, 1.1199, 1.1206, 1.1216, 1.1225, 1.1235,
1.1242, 1.1252, 1.1262, 1.1272, 1.1283, 1.1292, 1.1298, 1.1304,
1.131, 1.1314, 1.1315, 1.1316, 1.1319, 1.1319, 1.1318, 1.1315,
1.1312, 1.131, 1.1308, 1.1309, 1.1308, 1.1312, 1.1315, 1.1317,
1.1318, 1.1317, 1.1314, 1.1312, 1.1308, 1.1305, 1.1302, 1.13,
1.1298, 1.1295, 1.1296, 1.1298, 1.1295, 1.1289, 1.1283, 1.128,
1.1276, 1.1274, 1.1272, 1.1267, 1.1263, 1.1257, 1.1249, 1.124,
1.1231, 1.1223, 1.1217, 1.121, 1.1204, 1.1197, 1.1189, 1.1182,
1.1175, 1.1168, 1.1162, 1.1159, 1.1156, 1.1155, 1.1154, 1.1156,
1.1156, 1.1154, 1.1154, 1.1153, 1.1152, 1.1152, 1.1152, 1.1148,
1.1144, 1.1143, 1.1141, 1.1141, 1.1143, 1.1144, 1.1145, 1.1146,
1.1147, 1.1145, 1.1143, 1.1141, 1.1138, 1.1134, 1.1135, 1.1137,
1.1141, 1.1143, 1.1147, 1.1148, 1.115, 1.1153, 1.1156, 1.116,
1.1162, 1.1164, 1.1166, 1.1168, 1.117, 1.1173, 1.1177, 1.1181,
1.1185, 1.1189, 1.1194, 1.1198, 1.1203, 1.1206, 1.1207, 1.1208,
1.1207, 1.1204, 1.1201, 1.1199, 1.1197, 1.1195, 1.1193, 1.1189,
1.1184, 1.1179, 1.1173, 1.1165, 1.1157, 1.1148, 1.1141, 1.1135,
1.113, 1.1126, 1.1123, 1.1122, 1.1119, 1.1116, 1.1111, 1.1105,
1.1099, 1.1091, 1.108, 1.1069, 1.1057, 1.1044, 1.1032, 1.102,
1.1006, 1.0992, 1.0981, 1.097, 1.096, 1.0948, 1.0937, 1.0925,
1.0916, 1.0906, 1.0896, 1.0884, 1.0871, 1.0859, 1.0848, 1.0834,
1.082, 1.0805, 1.079, 1.0777, 1.0765, 1.0753, 1.0742, 1.0731,
1.0721, 1.071, 1.0701, 1.0693, 1.0685, 1.0675, 1.0667, 1.0661,
1.0652, 1.0644, 1.0634, 1.0624, 1.0614, 1.0604, 1.0595, 1.0589,
1.0583, 1.0578, 1.0575, 1.0576, 1.0576, 1.0577, 1.0578, 1.0581,
1.0582, 1.0585, 1.059, 1.0594, 1.0598, 1.06, 1.0601, 1.0603,
1.0603, 1.0603, 1.0599, 1.0597, 1.0594, 1.0595, 1.0596, 1.0595,
1.0594, 1.0594, 1.0597), index = structure(c(1409202000, 1409288400,
1409547600, 1409634000, 1409720400, 1409806800, 1409893200, 1410152400,
1410238800, 1410325200, 1410411600, 1410498000, 1410757200, 1410843600,
1410930000, 1411016400, 1411102800, 1411362000, 1411448400, 1411534800,
1411621200, 1411707600, 1411966800, 1412053200, 1412139600, 1412226000,
1412312400, 1412571600, 1412658000, 1412744400, 1412830800, 1412917200,
1413176400, 1413262800, 1413349200, 1413435600, 1413522000, 1413781200,
1413867600, 1413954000, 1414040400, 1414126800, 1414386000, 1414472400,
1414558800, 1414645200, 1414731600, 1414994400, 1415080800, 1415167200,
1415253600, 1415340000, 1415599200, 1415685600, 1415772000, 1415858400,
1415944800, 1416204000, 1416290400, 1416376800, 1416463200, 1416549600,
1416808800, 1416895200, 1416981600, 1417068000, 1417154400, 1417413600,
1417500000, 1417586400, 1417672800, 1417759200, 1418018400, 1418104800,
1418191200, 1418277600, 1418364000, 1418623200, 1418709600, 1418796000,
1418882400, 1418968800, 1419228000, 1419314400, 1419400800, 1419487200,
1419573600, 1419832800, 1419919200, 1420005600, 1420092000, 1420178400,
1420437600, 1420524000, 1420610400, 1420696800, 1420783200, 1421042400,
1421128800, 1421215200, 1421301600, 1421388000, 1421647200, 1421733600,
1421820000, 1421906400, 1421992800, 1422252000, 1422338400, 1422424800,
1422511200, 1422597600, 1422856800, 1422943200, 1423029600, 1423116000,
1423202400, 1423461600, 1423548000, 1423634400, 1423720800, 1423807200,
1424066400, 1424152800, 1424239200, 1424325600, 1424412000, 1424671200,
1424757600, 1424844000, 1424930400, 1425016800, 1425276000, 1425362400,
1425448800, 1425535200, 1425621600, 1425877200, 1425963600, 1426050000,
1426136400, 1426222800, 1426482000, 1426568400, 1426654800, 1426741200,
1426827600, 1427086800, 1427173200, 1427259600, 1427346000, 1427432400,
1427691600, 1427778000, 1427864400, 1427950800, 1428037200, 1428296400,
1428382800, 1428469200, 1428555600, 1428642000, 1428901200, 1428987600,
1429074000, 1429160400, 1429246800, 1429506000, 1429592400, 1429678800,
1429765200, 1429851600, 1430110800, 1430197200, 1430283600, 1430370000,
1430456400, 1430715600, 1430802000, 1430888400, 1430974800, 1431061200,
1431320400, 1431406800, 1431493200, 1431579600, 1431666000, 1431925200,
1432011600, 1432098000, 1432184400, 1432270800, 1432530000, 1432616400,
1432702800, 1432789200, 1432875600, 1433134800, 1433221200, 1433307600,
1433394000, 1433480400, 1433739600, 1433826000, 1433912400, 1433998800,
1434085200, 1434344400, 1434430800, 1434517200, 1434603600, 1434690000,
1434949200, 1435035600, 1435122000, 1435208400, 1435294800, 1435554000,
1435640400, 1435726800, 1435813200, 1435899600, 1436158800, 1436245200,
1436331600, 1436418000, 1436504400, 1436763600, 1436850000, 1436936400,
1437022800, 1437109200, 1437368400, 1437454800, 1437541200, 1437627600,
1437714000, 1437973200, 1438059600, 1438146000, 1438232400, 1438318800,
1438578000, 1438664400, 1438750800, 1438837200, 1438923600, 1439182800,
1439269200, 1439355600, 1439442000, 1439528400, 1439787600, 1439874000,
1439960400, 1440046800, 1440133200, 1440392400, 1440478800, 1440565200,
1440651600, 1440738000, 1440997200, 1441083600, 1441170000, 1441256400,
1441342800, 1441602000, 1441688400, 1441774800, 1441861200, 1441947600,
1442206800, 1442293200, 1442379600, 1442466000, 1442552400, 1442811600,
1442898000, 1442984400, 1443070800, 1443157200, 1443416400, 1443502800,
1443589200, 1443675600, 1443762000, 1444021200, 1444107600, 1444194000,
1444280400, 1444366800, 1444626000, 1444712400, 1444798800, 1444885200,
1444971600, 1445230800, 1445317200, 1445403600, 1445490000, 1445576400,
1445835600, 1445922000, 1446008400, 1446094800, 1446181200, 1446444000,
1446530400, 1446616800, 1446703200, 1446789600, 1447048800, 1447135200,
1447221600, 1447308000, 1447394400, 1447653600, 1447740000, 1447826400,
1447912800, 1447999200, 1448258400, 1448344800, 1448431200, 1448517600,
1448604000, 1448863200, 1448949600, 1449036000, 1449122400, 1449208800,
1449468000, 1449554400, 1449640800, 1449727200, 1449813600, 1450072800,
1450159200, 1450245600, 1450332000, 1450418400, 1450677600, 1450764000,
1450850400, 1450936800, 1451023200, 1451282400, 1451368800, 1451455200,
1451541600, 1451628000, 1451887200, 1451973600, 1452060000, 1452146400,
1452232800, 1452492000, 1452578400, 1452664800, 1452751200, 1452837600,
1453096800, 1453183200, 1453269600, 1453356000, 1453442400, 1453701600,
1453788000, 1453874400, 1453960800, 1454047200, 1454306400, 1454392800,
1454479200, 1454565600, 1454652000, 1454911200, 1454997600, 1455084000,
1455170400, 1455256800, 1455516000, 1455602400, 1455688800, 1455775200,
1455861600, 1456120800, 1456207200, 1456293600, 1456380000, 1456466400,
1456725600, 1456812000, 1456898400, 1456984800, 1457071200, 1457330400,
1457416800, 1457503200, 1457589600, 1457676000, 1457931600, 1458018000,
1458104400, 1458190800, 1458277200, 1458536400, 1458622800, 1458709200,
1458795600, 1458882000, 1459141200, 1459227600, 1459314000, 1459400400,
1459486800, 1459746000, 1459832400, 1459918800, 1460005200, 1460091600,
1460350800, 1460437200, 1460523600, 1460610000, 1460696400, 1460955600,
1461042000, 1461128400, 1461214800, 1461301200, 1461560400, 1461646800,
1461733200, 1461819600, 1461906000, 1462165200, 1462251600, 1462338000,
1462424400, 1462510800, 1462770000, 1462856400, 1462942800, 1463029200,
1463115600, 1463374800, 1463461200, 1463547600, 1463634000, 1463720400,
1463979600, 1464066000, 1464152400, 1464238800, 1464325200, 1464584400,
1464670800, 1464757200, 1464843600, 1464930000, 1465189200, 1465275600,
1465362000, 1465448400, 1465534800, 1465794000, 1465880400, 1465966800,
1466053200, 1466139600, 1466398800, 1466485200, 1466571600, 1466658000,
1466744400, 1467003600, 1467090000, 1467176400, 1467262800, 1467349200,
1467608400, 1467694800, 1467781200, 1467867600, 1467954000, 1468213200,
1468299600, 1468386000, 1468472400, 1468558800, 1468818000, 1468904400,
1468990800, 1469077200, 1469163600, 1469422800, 1469509200, 1469595600,
1469682000, 1469768400, 1470027600, 1470114000, 1470200400, 1470286800,
1470373200, 1470632400, 1470718800, 1470805200, 1470891600, 1470978000,
1471237200, 1471323600, 1471410000, 1471496400, 1471582800, 1471842000,
1471928400, 1472014800, 1472101200, 1472187600, 1472446800, 1472533200,
1472619600, 1472706000, 1472792400, 1473051600, 1473138000, 1473224400,
1473310800, 1473397200, 1473656400, 1473742800, 1473829200, 1473915600,
1474002000, 1474261200, 1474347600, 1474434000, 1474520400, 1474606800,
1474866000, 1474952400, 1475038800, 1475125200, 1475211600, 1475470800,
1475557200, 1475643600, 1475730000, 1475816400, 1476075600, 1476162000,
1476248400, 1476334800, 1476421200, 1476680400, 1476766800, 1476853200,
1476939600, 1477026000, 1477285200, 1477371600, 1477458000, 1477544400,
1477630800, 1477890000, 1477976400, 1478062800, 1478149200, 1478235600,
1478498400, 1478584800, 1478671200, 1478757600, 1478844000, 1479103200,
1479189600, 1479276000, 1479362400, 1479448800, 1479708000, 1479794400,
1479880800, 1479967200, 1480053600, 1480312800, 1480399200, 1480485600,
1480572000, 1480658400, 1480917600, 1481004000, 1481090400, 1481176800,
1481263200, 1481522400, 1481608800, 1481695200, 1481781600, 1481868000,
1482127200, 1482213600, 1482300000, 1482386400, 1482472800, 1482732000,
1482818400, 1482904800, 1482991200, 1483077600, 1483336800, 1483423200,
1483509600, 1483596000, 1483682400, 1483941600, 1484028000, 1484114400,
1484200800, 1484287200, 1484546400, 1484632800, 1484719200, 1484805600,
1484892000, 1485151200, 1485237600, 1485324000, 1485410400, 1485496800,
1485756000, 1485842400, 1485928800, 1486015200, 1486101600, 1486360800,
1486447200, 1486533600, 1486620000, 1486706400, 1486965600, 1487052000,
1487138400, 1487224800, 1487311200, 1487570400, 1487656800, 1487743200,
1487829600), tzone = "", tclass = c("POSIXct", "POSIXt")), .indexCLASS = c("POSIXct",
"POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "", class = c("xts",
"zoo"), .Dim = c(651L, 2L), .Dimnames = list(NULL, c("EUR.20D",
"EUR.50D")))
不,有 10 个交叉点。您可以使用 diff
、sign
和 which
:
df1[which(diff(sign(df1[,1]-df1[,2]))!=0),]
EUR.20D EUR.50D
2015-05-06 01:00:00 1.0887 1.0870
2015-07-13 01:00:00 1.1168 1.1174
2015-08-25 01:00:00 1.1100 1.1091
2015-10-27 01:00:00 1.1256 1.1260
2015-12-25 01:00:00 1.0878 1.0869
2016-05-30 01:00:00 1.1295 1.1310
2016-08-19 01:00:00 1.1158 1.1143
2016-10-07 01:00:00 1.1208 1.1208
2016-10-10 01:00:00 1.1204 1.1207
2017-01-24 01:00:00 1.0584 1.0576