diff --git a/DESCRIPTION b/DESCRIPTION index b165ba4a1..80ed27e1a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,7 +41,9 @@ Suggests: knitr, plotly, rmarkdown, - testthat (>= 3.0.0) + testthat (>= 3.0.0), + xts, + zoo Config/testthat/edition: 3 Depends: R (>= 3.5) diff --git a/NAMESPACE b/NAMESPACE index b03a1bff8..7f7450705 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,285 +1,344 @@ # Generated by roxygen2: do not edit by hand S3method("$",chart_theme) +S3method("[[",ta_series) S3method(.DollarNames,chart_theme) S3method(abandoned_baby,data.frame) S3method(abandoned_baby,default) S3method(abandoned_baby,ggplot) S3method(abandoned_baby,matrix) S3method(abandoned_baby,plotly) +S3method(abandoned_baby,xts) S3method(absolute_price_oscillator,data.frame) S3method(absolute_price_oscillator,default) S3method(absolute_price_oscillator,ggplot) S3method(absolute_price_oscillator,matrix) S3method(absolute_price_oscillator,numeric) S3method(absolute_price_oscillator,plotly) +S3method(absolute_price_oscillator,xts) S3method(acceleration_bands,data.frame) S3method(acceleration_bands,default) S3method(acceleration_bands,ggplot) S3method(acceleration_bands,matrix) S3method(acceleration_bands,plotly) +S3method(acceleration_bands,xts) S3method(advance_block,data.frame) S3method(advance_block,default) S3method(advance_block,ggplot) S3method(advance_block,matrix) S3method(advance_block,plotly) +S3method(advance_block,xts) S3method(aroon,data.frame) S3method(aroon,default) S3method(aroon,ggplot) S3method(aroon,matrix) S3method(aroon,plotly) +S3method(aroon,xts) S3method(aroon_oscillator,data.frame) S3method(aroon_oscillator,default) S3method(aroon_oscillator,ggplot) S3method(aroon_oscillator,matrix) S3method(aroon_oscillator,plotly) +S3method(aroon_oscillator,xts) +S3method(as.data.frame,ta_object) S3method(as.maType,double) S3method(as.maType,integer) S3method(as.maType,maType) +S3method(as.matrix,ta_object) +S3method(as.xts,ta_object) S3method(average_deviation,data.frame) S3method(average_deviation,default) S3method(average_deviation,matrix) S3method(average_deviation,numeric) +S3method(average_deviation,xts) S3method(average_directional_movement_index,data.frame) S3method(average_directional_movement_index,default) S3method(average_directional_movement_index,ggplot) S3method(average_directional_movement_index,matrix) S3method(average_directional_movement_index,plotly) +S3method(average_directional_movement_index,xts) S3method(average_directional_movement_index_rating,data.frame) S3method(average_directional_movement_index_rating,default) S3method(average_directional_movement_index_rating,ggplot) S3method(average_directional_movement_index_rating,matrix) S3method(average_directional_movement_index_rating,plotly) +S3method(average_directional_movement_index_rating,xts) S3method(average_price,data.frame) S3method(average_price,default) S3method(average_price,matrix) +S3method(average_price,xts) S3method(average_true_range,data.frame) S3method(average_true_range,default) S3method(average_true_range,ggplot) S3method(average_true_range,matrix) S3method(average_true_range,plotly) +S3method(average_true_range,xts) S3method(balance_of_power,data.frame) S3method(balance_of_power,default) S3method(balance_of_power,ggplot) S3method(balance_of_power,matrix) S3method(balance_of_power,plotly) +S3method(balance_of_power,xts) S3method(belt_hold,data.frame) S3method(belt_hold,default) S3method(belt_hold,ggplot) S3method(belt_hold,matrix) S3method(belt_hold,plotly) +S3method(belt_hold,xts) S3method(bollinger_bands,data.frame) S3method(bollinger_bands,default) S3method(bollinger_bands,ggplot) S3method(bollinger_bands,matrix) S3method(bollinger_bands,numeric) S3method(bollinger_bands,plotly) +S3method(bollinger_bands,xts) S3method(break_away,data.frame) S3method(break_away,default) S3method(break_away,ggplot) S3method(break_away,matrix) S3method(break_away,plotly) +S3method(break_away,xts) S3method(build_plotly,plotly) S3method(chaikin_accumulation_distribution_line,data.frame) S3method(chaikin_accumulation_distribution_line,default) S3method(chaikin_accumulation_distribution_line,ggplot) S3method(chaikin_accumulation_distribution_line,matrix) S3method(chaikin_accumulation_distribution_line,plotly) +S3method(chaikin_accumulation_distribution_line,xts) S3method(chaikin_accumulation_distribution_oscillator,data.frame) S3method(chaikin_accumulation_distribution_oscillator,default) S3method(chaikin_accumulation_distribution_oscillator,ggplot) S3method(chaikin_accumulation_distribution_oscillator,matrix) S3method(chaikin_accumulation_distribution_oscillator,plotly) +S3method(chaikin_accumulation_distribution_oscillator,xts) S3method(chaikin_money_flow,data.frame) S3method(chaikin_money_flow,default) S3method(chaikin_money_flow,ggplot) S3method(chaikin_money_flow,matrix) S3method(chaikin_money_flow,plotly) +S3method(chaikin_money_flow,xts) S3method(chande_momentum_oscillator,data.frame) S3method(chande_momentum_oscillator,default) S3method(chande_momentum_oscillator,ggplot) S3method(chande_momentum_oscillator,matrix) S3method(chande_momentum_oscillator,numeric) S3method(chande_momentum_oscillator,plotly) +S3method(chande_momentum_oscillator,xts) S3method(chart,default) S3method(closing_marubozu,data.frame) S3method(closing_marubozu,default) S3method(closing_marubozu,ggplot) S3method(closing_marubozu,matrix) S3method(closing_marubozu,plotly) +S3method(closing_marubozu,xts) S3method(commodity_channel_index,data.frame) S3method(commodity_channel_index,default) S3method(commodity_channel_index,ggplot) S3method(commodity_channel_index,matrix) S3method(commodity_channel_index,plotly) +S3method(commodity_channel_index,xts) S3method(concealing_baby_swallow,data.frame) S3method(concealing_baby_swallow,default) S3method(concealing_baby_swallow,ggplot) S3method(concealing_baby_swallow,matrix) S3method(concealing_baby_swallow,plotly) +S3method(concealing_baby_swallow,xts) S3method(counter_attack,data.frame) S3method(counter_attack,default) S3method(counter_attack,ggplot) S3method(counter_attack,matrix) S3method(counter_attack,plotly) +S3method(counter_attack,xts) S3method(dark_cloud_cover,data.frame) S3method(dark_cloud_cover,default) S3method(dark_cloud_cover,ggplot) S3method(dark_cloud_cover,matrix) S3method(dark_cloud_cover,plotly) +S3method(dark_cloud_cover,xts) S3method(directional_movement_index,data.frame) S3method(directional_movement_index,default) S3method(directional_movement_index,ggplot) S3method(directional_movement_index,matrix) S3method(directional_movement_index,plotly) +S3method(directional_movement_index,xts) S3method(doji,data.frame) S3method(doji,default) S3method(doji,ggplot) S3method(doji,matrix) S3method(doji,plotly) +S3method(doji,xts) S3method(doji_star,data.frame) S3method(doji_star,default) S3method(doji_star,ggplot) S3method(doji_star,matrix) S3method(doji_star,plotly) +S3method(doji_star,xts) S3method(dominant_cycle_period,data.frame) S3method(dominant_cycle_period,default) S3method(dominant_cycle_period,ggplot) S3method(dominant_cycle_period,matrix) S3method(dominant_cycle_period,numeric) S3method(dominant_cycle_period,plotly) +S3method(dominant_cycle_period,xts) S3method(dominant_cycle_phase,data.frame) S3method(dominant_cycle_phase,default) S3method(dominant_cycle_phase,ggplot) S3method(dominant_cycle_phase,matrix) S3method(dominant_cycle_phase,numeric) S3method(dominant_cycle_phase,plotly) +S3method(dominant_cycle_phase,xts) S3method(double_exponential_moving_average,data.frame) S3method(double_exponential_moving_average,default) S3method(double_exponential_moving_average,ggplot) S3method(double_exponential_moving_average,matrix) S3method(double_exponential_moving_average,numeric) S3method(double_exponential_moving_average,plotly) +S3method(double_exponential_moving_average,xts) S3method(dragonfly_doji,data.frame) S3method(dragonfly_doji,default) S3method(dragonfly_doji,ggplot) S3method(dragonfly_doji,matrix) S3method(dragonfly_doji,plotly) +S3method(dragonfly_doji,xts) S3method(engulfing,data.frame) S3method(engulfing,default) S3method(engulfing,ggplot) S3method(engulfing,matrix) S3method(engulfing,plotly) +S3method(engulfing,xts) S3method(evening_doji_star,data.frame) S3method(evening_doji_star,default) S3method(evening_doji_star,ggplot) S3method(evening_doji_star,matrix) S3method(evening_doji_star,plotly) +S3method(evening_doji_star,xts) S3method(evening_star,data.frame) S3method(evening_star,default) S3method(evening_star,ggplot) S3method(evening_star,matrix) S3method(evening_star,plotly) +S3method(evening_star,xts) S3method(exponential_moving_average,data.frame) S3method(exponential_moving_average,default) S3method(exponential_moving_average,ggplot) S3method(exponential_moving_average,matrix) S3method(exponential_moving_average,numeric) S3method(exponential_moving_average,plotly) +S3method(exponential_moving_average,xts) S3method(extended_moving_average_convergence_divergence,data.frame) S3method(extended_moving_average_convergence_divergence,default) S3method(extended_moving_average_convergence_divergence,ggplot) S3method(extended_moving_average_convergence_divergence,matrix) S3method(extended_moving_average_convergence_divergence,numeric) S3method(extended_moving_average_convergence_divergence,plotly) +S3method(extended_moving_average_convergence_divergence,xts) S3method(extended_parabolic_stop_and_reverse,data.frame) S3method(extended_parabolic_stop_and_reverse,default) S3method(extended_parabolic_stop_and_reverse,ggplot) S3method(extended_parabolic_stop_and_reverse,matrix) S3method(extended_parabolic_stop_and_reverse,plotly) +S3method(extended_parabolic_stop_and_reverse,xts) S3method(fast_stochastic,data.frame) S3method(fast_stochastic,default) S3method(fast_stochastic,ggplot) S3method(fast_stochastic,matrix) S3method(fast_stochastic,plotly) +S3method(fast_stochastic,xts) S3method(fixed_moving_average_convergence_divergence,data.frame) S3method(fixed_moving_average_convergence_divergence,default) S3method(fixed_moving_average_convergence_divergence,ggplot) S3method(fixed_moving_average_convergence_divergence,matrix) S3method(fixed_moving_average_convergence_divergence,numeric) S3method(fixed_moving_average_convergence_divergence,plotly) +S3method(fixed_moving_average_convergence_divergence,xts) S3method(gaps_side_white,data.frame) S3method(gaps_side_white,default) S3method(gaps_side_white,ggplot) S3method(gaps_side_white,matrix) S3method(gaps_side_white,plotly) +S3method(gaps_side_white,xts) S3method(gravestone_doji,data.frame) S3method(gravestone_doji,default) S3method(gravestone_doji,ggplot) S3method(gravestone_doji,matrix) S3method(gravestone_doji,plotly) +S3method(gravestone_doji,xts) S3method(hammer,data.frame) S3method(hammer,default) S3method(hammer,ggplot) S3method(hammer,matrix) S3method(hammer,plotly) +S3method(hammer,xts) S3method(hanging_man,data.frame) S3method(hanging_man,default) S3method(hanging_man,ggplot) S3method(hanging_man,matrix) S3method(hanging_man,plotly) +S3method(hanging_man,xts) S3method(harami,data.frame) S3method(harami,default) S3method(harami,ggplot) S3method(harami,matrix) S3method(harami,plotly) +S3method(harami,xts) S3method(harami_cross,data.frame) S3method(harami_cross,default) S3method(harami_cross,ggplot) S3method(harami_cross,matrix) S3method(harami_cross,plotly) +S3method(harami_cross,xts) S3method(high_wave,data.frame) S3method(high_wave,default) S3method(high_wave,ggplot) S3method(high_wave,matrix) S3method(high_wave,plotly) +S3method(high_wave,xts) S3method(hikakke,data.frame) S3method(hikakke,default) S3method(hikakke,ggplot) S3method(hikakke,matrix) S3method(hikakke,plotly) +S3method(hikakke,xts) S3method(hikakke_mod,data.frame) S3method(hikakke_mod,default) S3method(hikakke_mod,ggplot) S3method(hikakke_mod,matrix) S3method(hikakke_mod,plotly) +S3method(hikakke_mod,xts) S3method(homing_pigeon,data.frame) S3method(homing_pigeon,default) S3method(homing_pigeon,ggplot) S3method(homing_pigeon,matrix) S3method(homing_pigeon,plotly) +S3method(homing_pigeon,xts) S3method(hull_moving_average,data.frame) S3method(hull_moving_average,default) S3method(hull_moving_average,ggplot) S3method(hull_moving_average,matrix) S3method(hull_moving_average,numeric) S3method(hull_moving_average,plotly) +S3method(hull_moving_average,xts) S3method(in_neck,data.frame) S3method(in_neck,default) S3method(in_neck,ggplot) S3method(in_neck,matrix) S3method(in_neck,plotly) +S3method(in_neck,xts) +S3method(index,default) +S3method(index,xts) S3method(indicator,"function") S3method(intraday_movement_index,data.frame) S3method(intraday_movement_index,default) S3method(intraday_movement_index,ggplot) S3method(intraday_movement_index,matrix) S3method(intraday_movement_index,plotly) +S3method(intraday_movement_index,xts) S3method(inverted_hammer,data.frame) S3method(inverted_hammer,default) S3method(inverted_hammer,ggplot) S3method(inverted_hammer,matrix) S3method(inverted_hammer,plotly) +S3method(inverted_hammer,xts) S3method(is.empty,character) S3method(is.empty,default) S3method(is.empty,list) @@ -289,168 +348,201 @@ S3method(kaufman_adaptive_moving_average,ggplot) S3method(kaufman_adaptive_moving_average,matrix) S3method(kaufman_adaptive_moving_average,numeric) S3method(kaufman_adaptive_moving_average,plotly) +S3method(kaufman_adaptive_moving_average,xts) S3method(kicking,data.frame) S3method(kicking,default) S3method(kicking,ggplot) S3method(kicking,matrix) S3method(kicking,plotly) +S3method(kicking,xts) S3method(kicking_baby_length,data.frame) S3method(kicking_baby_length,default) S3method(kicking_baby_length,ggplot) S3method(kicking_baby_length,matrix) S3method(kicking_baby_length,plotly) +S3method(kicking_baby_length,xts) S3method(ladder_bottom,data.frame) S3method(ladder_bottom,default) S3method(ladder_bottom,ggplot) S3method(ladder_bottom,matrix) S3method(ladder_bottom,plotly) +S3method(ladder_bottom,xts) S3method(long_legged_doji,data.frame) S3method(long_legged_doji,default) S3method(long_legged_doji,ggplot) S3method(long_legged_doji,matrix) S3method(long_legged_doji,plotly) +S3method(long_legged_doji,xts) S3method(long_line,data.frame) S3method(long_line,default) S3method(long_line,ggplot) S3method(long_line,matrix) S3method(long_line,plotly) +S3method(long_line,xts) S3method(map_dfr,double) S3method(map_dfr,integer) +S3method(map_dfr,ta_object) S3method(marubozu,data.frame) S3method(marubozu,default) S3method(marubozu,ggplot) S3method(marubozu,matrix) S3method(marubozu,plotly) +S3method(marubozu,xts) S3method(mat_hold,data.frame) S3method(mat_hold,default) S3method(mat_hold,ggplot) S3method(mat_hold,matrix) S3method(mat_hold,plotly) +S3method(mat_hold,xts) S3method(matching_low,data.frame) S3method(matching_low,default) S3method(matching_low,ggplot) S3method(matching_low,matrix) S3method(matching_low,plotly) +S3method(matching_low,xts) S3method(median_price,data.frame) S3method(median_price,default) S3method(median_price,matrix) +S3method(median_price,xts) S3method(mesa_adaptive_moving_average,data.frame) S3method(mesa_adaptive_moving_average,default) S3method(mesa_adaptive_moving_average,ggplot) S3method(mesa_adaptive_moving_average,matrix) S3method(mesa_adaptive_moving_average,numeric) S3method(mesa_adaptive_moving_average,plotly) +S3method(mesa_adaptive_moving_average,xts) S3method(midpoint_period,data.frame) S3method(midpoint_period,default) S3method(midpoint_period,ggplot) S3method(midpoint_period,matrix) S3method(midpoint_period,numeric) S3method(midpoint_period,plotly) +S3method(midpoint_period,xts) S3method(midpoint_price,data.frame) S3method(midpoint_price,default) S3method(midpoint_price,ggplot) S3method(midpoint_price,matrix) S3method(midpoint_price,plotly) +S3method(midpoint_price,xts) S3method(minus_directional_indicator,data.frame) S3method(minus_directional_indicator,default) S3method(minus_directional_indicator,ggplot) S3method(minus_directional_indicator,matrix) S3method(minus_directional_indicator,plotly) +S3method(minus_directional_indicator,xts) S3method(minus_directional_movement,data.frame) S3method(minus_directional_movement,default) S3method(minus_directional_movement,ggplot) S3method(minus_directional_movement,matrix) S3method(minus_directional_movement,plotly) +S3method(minus_directional_movement,xts) S3method(momentum,data.frame) S3method(momentum,default) S3method(momentum,ggplot) S3method(momentum,matrix) S3method(momentum,numeric) S3method(momentum,plotly) +S3method(momentum,xts) S3method(money_flow_index,data.frame) S3method(money_flow_index,default) S3method(money_flow_index,ggplot) S3method(money_flow_index,matrix) S3method(money_flow_index,plotly) +S3method(money_flow_index,xts) S3method(morning_doji_star,data.frame) S3method(morning_doji_star,default) S3method(morning_doji_star,ggplot) S3method(morning_doji_star,matrix) S3method(morning_doji_star,plotly) +S3method(morning_doji_star,xts) S3method(morning_star,data.frame) S3method(morning_star,default) S3method(morning_star,ggplot) S3method(morning_star,matrix) S3method(morning_star,plotly) +S3method(morning_star,xts) S3method(moving_average_convergence_divergence,data.frame) S3method(moving_average_convergence_divergence,default) S3method(moving_average_convergence_divergence,ggplot) S3method(moving_average_convergence_divergence,matrix) S3method(moving_average_convergence_divergence,numeric) S3method(moving_average_convergence_divergence,plotly) +S3method(moving_average_convergence_divergence,xts) S3method(negative_volume_index,data.frame) S3method(negative_volume_index,default) S3method(negative_volume_index,ggplot) S3method(negative_volume_index,matrix) S3method(negative_volume_index,plotly) +S3method(negative_volume_index,xts) S3method(normalized_average_true_range,data.frame) S3method(normalized_average_true_range,default) S3method(normalized_average_true_range,ggplot) S3method(normalized_average_true_range,matrix) S3method(normalized_average_true_range,plotly) +S3method(normalized_average_true_range,xts) S3method(on_balance_volume,data.frame) S3method(on_balance_volume,default) S3method(on_balance_volume,ggplot) S3method(on_balance_volume,matrix) S3method(on_balance_volume,plotly) +S3method(on_balance_volume,xts) S3method(on_neck,data.frame) S3method(on_neck,default) S3method(on_neck,ggplot) S3method(on_neck,matrix) S3method(on_neck,plotly) +S3method(on_neck,xts) S3method(parabolic_stop_and_reverse,data.frame) S3method(parabolic_stop_and_reverse,default) S3method(parabolic_stop_and_reverse,ggplot) S3method(parabolic_stop_and_reverse,matrix) S3method(parabolic_stop_and_reverse,plotly) +S3method(parabolic_stop_and_reverse,xts) S3method(percentage_price_oscillator,data.frame) S3method(percentage_price_oscillator,default) S3method(percentage_price_oscillator,ggplot) S3method(percentage_price_oscillator,matrix) S3method(percentage_price_oscillator,numeric) S3method(percentage_price_oscillator,plotly) +S3method(percentage_price_oscillator,xts) S3method(percentage_volume_oscillator,data.frame) S3method(percentage_volume_oscillator,default) S3method(percentage_volume_oscillator,ggplot) S3method(percentage_volume_oscillator,matrix) S3method(percentage_volume_oscillator,numeric) S3method(percentage_volume_oscillator,plotly) +S3method(percentage_volume_oscillator,xts) S3method(phasor_components,data.frame) S3method(phasor_components,default) S3method(phasor_components,ggplot) S3method(phasor_components,matrix) S3method(phasor_components,numeric) S3method(phasor_components,plotly) +S3method(phasor_components,xts) S3method(piercing,data.frame) S3method(piercing,default) S3method(piercing,ggplot) S3method(piercing,matrix) S3method(piercing,plotly) +S3method(piercing,xts) S3method(plus_directional_indicator,data.frame) S3method(plus_directional_indicator,default) S3method(plus_directional_indicator,ggplot) S3method(plus_directional_indicator,matrix) S3method(plus_directional_indicator,plotly) +S3method(plus_directional_indicator,xts) S3method(plus_directional_movement,data.frame) S3method(plus_directional_movement,default) S3method(plus_directional_movement,ggplot) S3method(plus_directional_movement,matrix) S3method(plus_directional_movement,plotly) +S3method(plus_directional_movement,xts) S3method(positive_volume_index,data.frame) S3method(positive_volume_index,default) S3method(positive_volume_index,ggplot) S3method(positive_volume_index,matrix) S3method(positive_volume_index,plotly) +S3method(positive_volume_index,xts) S3method(print,talib_chart) S3method(print,talib_gg_chart) S3method(ratio_of_change,data.frame) @@ -459,44 +551,62 @@ S3method(ratio_of_change,ggplot) S3method(ratio_of_change,matrix) S3method(ratio_of_change,numeric) S3method(ratio_of_change,plotly) +S3method(ratio_of_change,xts) S3method(relative_strength_index,data.frame) S3method(relative_strength_index,default) S3method(relative_strength_index,ggplot) S3method(relative_strength_index,matrix) S3method(relative_strength_index,numeric) S3method(relative_strength_index,plotly) +S3method(relative_strength_index,xts) S3method(rickshaw_man,data.frame) S3method(rickshaw_man,default) S3method(rickshaw_man,ggplot) S3method(rickshaw_man,matrix) S3method(rickshaw_man,plotly) +S3method(rickshaw_man,xts) S3method(rise_fall_3_methods,data.frame) S3method(rise_fall_3_methods,default) S3method(rise_fall_3_methods,ggplot) S3method(rise_fall_3_methods,matrix) S3method(rise_fall_3_methods,plotly) +S3method(rise_fall_3_methods,xts) S3method(rolling_beta,default) S3method(rolling_beta,numeric) +S3method(rolling_beta,xts) S3method(rolling_correlation,default) S3method(rolling_correlation,numeric) +S3method(rolling_correlation,xts) S3method(rolling_maximum,default) S3method(rolling_maximum,numeric) +S3method(rolling_maximum,xts) S3method(rolling_minimum,default) S3method(rolling_minimum,numeric) +S3method(rolling_minimum,xts) S3method(rolling_standard_deviation,default) S3method(rolling_standard_deviation,numeric) +S3method(rolling_standard_deviation,xts) S3method(rolling_sum,default) S3method(rolling_sum,numeric) +S3method(rolling_sum,xts) S3method(rolling_variance,default) S3method(rolling_variance,numeric) +S3method(rolling_variance,xts) S3method(separating_lines,data.frame) S3method(separating_lines,default) S3method(separating_lines,ggplot) S3method(separating_lines,matrix) S3method(separating_lines,plotly) -S3method(series,formula) +S3method(separating_lines,xts) +S3method(series,data.frame) +S3method(series,default) S3method(series,ggplot) +S3method(series,matrix) S3method(series,plotly) +S3method(series,xts) +S3method(set_index,character) +S3method(set_index,default) +S3method(set_index,numeric) S3method(set_rownames,data.frame) S3method(set_rownames,matrix) S3method(shooting_star,data.frame) @@ -504,211 +614,251 @@ S3method(shooting_star,default) S3method(shooting_star,ggplot) S3method(shooting_star,matrix) S3method(shooting_star,plotly) +S3method(shooting_star,xts) S3method(short_line,data.frame) S3method(short_line,default) S3method(short_line,ggplot) S3method(short_line,matrix) S3method(short_line,plotly) +S3method(short_line,xts) S3method(simple_moving_average,data.frame) S3method(simple_moving_average,default) S3method(simple_moving_average,ggplot) S3method(simple_moving_average,matrix) S3method(simple_moving_average,numeric) S3method(simple_moving_average,plotly) +S3method(simple_moving_average,xts) S3method(sine_wave,data.frame) S3method(sine_wave,default) S3method(sine_wave,ggplot) S3method(sine_wave,matrix) S3method(sine_wave,numeric) S3method(sine_wave,plotly) +S3method(sine_wave,xts) S3method(spinning_top,data.frame) S3method(spinning_top,default) S3method(spinning_top,ggplot) S3method(spinning_top,matrix) S3method(spinning_top,plotly) +S3method(spinning_top,xts) S3method(stalled_pattern,data.frame) S3method(stalled_pattern,default) S3method(stalled_pattern,ggplot) S3method(stalled_pattern,matrix) S3method(stalled_pattern,plotly) +S3method(stalled_pattern,xts) S3method(stick_sandwich,data.frame) S3method(stick_sandwich,default) S3method(stick_sandwich,ggplot) S3method(stick_sandwich,matrix) S3method(stick_sandwich,plotly) +S3method(stick_sandwich,xts) S3method(stochastic,data.frame) S3method(stochastic,default) S3method(stochastic,ggplot) S3method(stochastic,matrix) S3method(stochastic,plotly) +S3method(stochastic,xts) S3method(stochastic_relative_strength_index,data.frame) S3method(stochastic_relative_strength_index,default) S3method(stochastic_relative_strength_index,ggplot) S3method(stochastic_relative_strength_index,matrix) S3method(stochastic_relative_strength_index,numeric) S3method(stochastic_relative_strength_index,plotly) +S3method(stochastic_relative_strength_index,xts) S3method(t3_exponential_moving_average,data.frame) S3method(t3_exponential_moving_average,default) S3method(t3_exponential_moving_average,ggplot) S3method(t3_exponential_moving_average,matrix) S3method(t3_exponential_moving_average,numeric) S3method(t3_exponential_moving_average,plotly) +S3method(t3_exponential_moving_average,xts) S3method(takuri,data.frame) S3method(takuri,default) S3method(takuri,ggplot) S3method(takuri,matrix) S3method(takuri,plotly) +S3method(takuri,xts) S3method(tasuki_gap,data.frame) S3method(tasuki_gap,default) S3method(tasuki_gap,ggplot) S3method(tasuki_gap,matrix) S3method(tasuki_gap,plotly) +S3method(tasuki_gap,xts) S3method(three_black_crows,data.frame) S3method(three_black_crows,default) S3method(three_black_crows,ggplot) S3method(three_black_crows,matrix) S3method(three_black_crows,plotly) +S3method(three_black_crows,xts) S3method(three_identical_crows,data.frame) S3method(three_identical_crows,default) S3method(three_identical_crows,ggplot) S3method(three_identical_crows,matrix) S3method(three_identical_crows,plotly) +S3method(three_identical_crows,xts) S3method(three_inside,data.frame) S3method(three_inside,default) S3method(three_inside,ggplot) S3method(three_inside,matrix) S3method(three_inside,plotly) +S3method(three_inside,xts) S3method(three_line_strike,data.frame) S3method(three_line_strike,default) S3method(three_line_strike,ggplot) S3method(three_line_strike,matrix) S3method(three_line_strike,plotly) +S3method(three_line_strike,xts) S3method(three_outside,data.frame) S3method(three_outside,default) S3method(three_outside,ggplot) S3method(three_outside,matrix) S3method(three_outside,plotly) +S3method(three_outside,xts) S3method(three_stars_in_the_south,data.frame) S3method(three_stars_in_the_south,default) S3method(three_stars_in_the_south,ggplot) S3method(three_stars_in_the_south,matrix) S3method(three_stars_in_the_south,plotly) +S3method(three_stars_in_the_south,xts) S3method(three_white_soldiers,data.frame) S3method(three_white_soldiers,default) S3method(three_white_soldiers,ggplot) S3method(three_white_soldiers,matrix) S3method(three_white_soldiers,plotly) +S3method(three_white_soldiers,xts) S3method(thrusting,data.frame) S3method(thrusting,default) S3method(thrusting,ggplot) S3method(thrusting,matrix) S3method(thrusting,plotly) +S3method(thrusting,xts) S3method(trading_volume,data.frame) S3method(trading_volume,default) S3method(trading_volume,ggplot) S3method(trading_volume,matrix) S3method(trading_volume,numeric) S3method(trading_volume,plotly) +S3method(trading_volume,xts) S3method(trend_cycle_mode,data.frame) S3method(trend_cycle_mode,default) S3method(trend_cycle_mode,ggplot) S3method(trend_cycle_mode,matrix) S3method(trend_cycle_mode,numeric) S3method(trend_cycle_mode,plotly) +S3method(trend_cycle_mode,xts) S3method(trendline,data.frame) S3method(trendline,default) S3method(trendline,ggplot) S3method(trendline,matrix) S3method(trendline,numeric) S3method(trendline,plotly) +S3method(trendline,xts) S3method(triangular_moving_average,data.frame) S3method(triangular_moving_average,default) S3method(triangular_moving_average,ggplot) S3method(triangular_moving_average,matrix) S3method(triangular_moving_average,numeric) S3method(triangular_moving_average,plotly) +S3method(triangular_moving_average,xts) S3method(triple_exponential_average,data.frame) S3method(triple_exponential_average,default) S3method(triple_exponential_average,ggplot) S3method(triple_exponential_average,matrix) S3method(triple_exponential_average,numeric) S3method(triple_exponential_average,plotly) +S3method(triple_exponential_average,xts) S3method(triple_exponential_moving_average,data.frame) S3method(triple_exponential_moving_average,default) S3method(triple_exponential_moving_average,ggplot) S3method(triple_exponential_moving_average,matrix) S3method(triple_exponential_moving_average,numeric) S3method(triple_exponential_moving_average,plotly) +S3method(triple_exponential_moving_average,xts) S3method(tristar,data.frame) S3method(tristar,default) S3method(tristar,ggplot) S3method(tristar,matrix) S3method(tristar,plotly) +S3method(tristar,xts) S3method(true_range,data.frame) S3method(true_range,default) S3method(true_range,ggplot) S3method(true_range,matrix) S3method(true_range,plotly) +S3method(true_range,xts) S3method(two_crows,data.frame) S3method(two_crows,default) S3method(two_crows,ggplot) S3method(two_crows,matrix) S3method(two_crows,plotly) +S3method(two_crows,xts) S3method(typical_price,data.frame) S3method(typical_price,default) S3method(typical_price,matrix) +S3method(typical_price,xts) S3method(ultimate_oscillator,data.frame) S3method(ultimate_oscillator,default) S3method(ultimate_oscillator,ggplot) S3method(ultimate_oscillator,matrix) S3method(ultimate_oscillator,plotly) +S3method(ultimate_oscillator,xts) S3method(unique_3_river,data.frame) S3method(unique_3_river,default) S3method(unique_3_river,ggplot) S3method(unique_3_river,matrix) S3method(unique_3_river,plotly) +S3method(unique_3_river,xts) S3method(unsmoothed_chande_momentum_oscillator,data.frame) S3method(unsmoothed_chande_momentum_oscillator,default) S3method(unsmoothed_chande_momentum_oscillator,ggplot) S3method(unsmoothed_chande_momentum_oscillator,matrix) S3method(unsmoothed_chande_momentum_oscillator,numeric) S3method(unsmoothed_chande_momentum_oscillator,plotly) +S3method(unsmoothed_chande_momentum_oscillator,xts) S3method(upside_gap_2_crows,data.frame) S3method(upside_gap_2_crows,default) S3method(upside_gap_2_crows,ggplot) S3method(upside_gap_2_crows,matrix) S3method(upside_gap_2_crows,plotly) +S3method(upside_gap_2_crows,xts) S3method(variable_moving_average_period,data.frame) S3method(variable_moving_average_period,default) S3method(variable_moving_average_period,ggplot) S3method(variable_moving_average_period,matrix) S3method(variable_moving_average_period,numeric) S3method(variable_moving_average_period,plotly) +S3method(variable_moving_average_period,xts) S3method(volume_weighted_moving_average,data.frame) S3method(volume_weighted_moving_average,default) S3method(volume_weighted_moving_average,ggplot) S3method(volume_weighted_moving_average,matrix) S3method(volume_weighted_moving_average,numeric) S3method(volume_weighted_moving_average,plotly) +S3method(volume_weighted_moving_average,xts) S3method(weighted_close_price,data.frame) S3method(weighted_close_price,default) S3method(weighted_close_price,matrix) +S3method(weighted_close_price,xts) S3method(weighted_moving_average,data.frame) S3method(weighted_moving_average,default) S3method(weighted_moving_average,ggplot) S3method(weighted_moving_average,matrix) S3method(weighted_moving_average,numeric) S3method(weighted_moving_average,plotly) +S3method(weighted_moving_average,xts) S3method(williams_oscillator,data.frame) S3method(williams_oscillator,default) S3method(williams_oscillator,ggplot) S3method(williams_oscillator,matrix) S3method(williams_oscillator,plotly) +S3method(williams_oscillator,xts) S3method(xside_gap_3_methods,data.frame) S3method(xside_gap_3_methods,default) S3method(xside_gap_3_methods,ggplot) S3method(xside_gap_3_methods,matrix) S3method(xside_gap_3_methods,plotly) +S3method(xside_gap_3_methods,xts) export(ACCBANDS) export(AD) export(ADOSC) diff --git a/NEWS.md b/NEWS.md index e6a89c34d..3364bf493 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,28 @@ Its use-case is customized control-flows for downstream wrappers and/or packages * The source code have been re-written so it generates the underlying TA-Lib wrappers using preprocessors and X-Macros, which compiles much faster than before. +* _**\**-methods:_—All indicators now supports \-objects. These methods are considered the primary entry point for *all* indicators, and can be considered stable from v1.0.0, where changes—if any—will be implemented gradually after a deprecation period. The method uses the same signature as before, see the example below: + +``` r +library(xts) + +tail( + x <- talib::bollinger_bands( + talib::GOOGL + ) +) +#> UpperBand MiddleBand LowerBand +#> 2021-12-22 149.1432 144.4920 139.8408 +#> 2021-12-23 149.2513 144.5318 139.8124 +#> 2021-12-27 149.6263 144.8180 140.0097 +#> 2021-12-28 149.7444 144.8758 140.0072 +#> 2021-12-29 149.8398 145.1137 140.3876 +#> 2021-12-30 149.7308 145.3711 141.0115 + +class(x) +#> [1] "xts" "zoo" +``` + * _**MAVP:** Moving Average Variable Periods_—The function calculates a moving average with variable periods between candles. See below: ```R diff --git a/R/GOOGL.R b/R/GOOGL.R new file mode 100644 index 000000000..4d3ffef02 --- /dev/null +++ b/R/GOOGL.R @@ -0,0 +1,36 @@ +#' @name GOOGL +#' @title Alphabet Inc. (GOOGL) +#' +#' @description +#' Daily OHLCV price data for Alphabet Inc. (GOOGL), denominated in +#' USD, covering 2019-01-01 to 2021-12-31. Stored as an `xts` object +#' with a `Date` index and quantmod-style prefixed column names - the +#' exact shape returned by `quantmod::getSymbols()` - and used by the +#' unit tests for the `xts` methods. +#' +#' @format An `xts` object with 756 rows and 6 columns. +#' +#' \describe{ +#' \item{GOOGL.Open}{Opening price for the trading day.} +#' \item{GOOGL.High}{Highest price reached during the trading day.} +#' \item{GOOGL.Low}{Lowest price reached during the trading day.} +#' \item{GOOGL.Close}{Closing price for the trading day.} +#' \item{GOOGL.Volume}{Total trading volume for the day.} +#' \item{GOOGL.Adjusted}{Adjusted closing price for the trading day.} +#' } +#' +#' @source Loaded using [quantmod](https://cran.r-project.org/web/packages/quantmod/index.html). +#' +#' @concept Financial Data +#' @concept OHLCV +#' +#' @docType data +#' @keywords datasets +#' +#' @examples +#' ## Load the dataset +#' data(GOOGL, package = "talib") +#' +#' ## Scan for Doji patterns on GOOGL +#' talib::doji(GOOGL) +"GOOGL" diff --git a/R/chart.R b/R/chart.R index 51de473c6..45512a7a0 100644 --- a/R/chart.R +++ b/R/chart.R @@ -169,6 +169,31 @@ chart.default <- function( ## convert input to data.frame and store in state x <- as.data.frame(x) + + ## normalize quantmod-style OHLCV names (TICKER.Close, Close) + ## to the lowercase names the chart backends consume - exact + ## matches win over dot-suffix matches, mirroring series.xts() + targets <- c("open", "high", "low", "close", "volume") + lowered <- tolower(colnames(x)) + exact_hits <- outer(targets, lowered, `==`) + suffix_hits <- outer( + paste0(".", targets), + lowered, + function(suffix, name) endsWith(name, suffix) + ) + suffix_hits[rowSums(exact_hits) > 0L, ] <- FALSE + hits <- exact_hits | suffix_hits + resolved <- rowSums(hits) == 1L + colnames(x)[max.col(hits, ties.method = "first")[resolved]] <- + targets[resolved] + + ## fail fast with the package's own message instead of a + ## deferred backend error at render time + assert_column_names( + formula = ~ open + high + low + close, + available_variables = colnames(x) + ) + x$idx <- if (is.null(idx)) { ## check if rownames can be ## converted to integer diff --git a/R/chart_build.R b/R/chart_build.R index b94aeb715..6375820d5 100644 --- a/R/chart_build.R +++ b/R/chart_build.R @@ -173,12 +173,18 @@ build_ggplot <- function( data <- data[-(1:lookback), , drop = FALSE] } - ## add position column aligned - ## with main chart x-axis - data$.chart_pos <- seq.int( - lookback + 1L, - lookback + nrow(data) - ) + ## add position column aligned with the main chart x-axis. + ## Aligning by label places subset indicators on their own + ## rows of the shared axis - mirroring the plotly backend, + ## which aligns by the idx labels themselves + chart_positions <- match(data$idx, .chart_state()$idx$label) + if (length(chart_positions) != nrow(data) || anyNA(chart_positions)) { + chart_positions <- seq.int( + lookback + 1L, + lookback + nrow(data) + ) + } + data$.chart_pos <- chart_positions ## replace missing name if (missing(name) || is.null(name)) { diff --git a/R/chart_indicator.R b/R/chart_indicator.R index 9496fe408..4468a2faa 100644 --- a/R/chart_indicator.R +++ b/R/chart_indicator.R @@ -221,8 +221,11 @@ indicator.function <- function(FUN, ...) { match.call()[["idx"]] ) } else { + ## rownames of the coerced frame so index-bearing + ## classes (xts) keep their time axis - a bare + ## rownames(data) is NULL for those idx <- rownames( - data + as.data.frame(data) ) } @@ -235,14 +238,29 @@ indicator.function <- function(FUN, ...) { state$x <- as.data.frame(data) } - ## dispatch to the appropriate backend method - ## based on the class of 'plt' - outcome <- do.call( - what = FUN, - args = list( - x = plt, - ... - ) + ## dispatch to the appropriate backend method based on the + ## class of 'plt'. Everything except 'subset' is forced + ## through its own promise; 'subset' stays quoted and the + ## call evaluates in the caller's frame, so model.frame() + ## sees it once, data-first, with the caller's objects as + ## fallback - identical to a direct wrapper call + dots_expr <- as.list(substitute(list(...)))[-1L] + dots_names <- names(dots_expr) + if (is.null(dots_names)) { + dots_names <- rep("", length(dots_expr)) + } + + dots_expr[] <- lapply(seq_along(dots_expr), function(i) { + if (identical(dots_names[[i]], "subset")) { + dots_expr[[i]] + } else { + ...elt(i) + } + }) + + outcome <- eval( + as.call(c(list(FUN), list(x = plt), dots_expr)), + parent.frame() ) ## verify return type @@ -687,7 +705,7 @@ assemble_ggplot2 <- function() { ## convert to grobs and align column widths ## so that y-axes line up across panels ## use a null device to prevent Rplots.pdf - grDevices::pdf(nullfile()) + grDevices::pdf(.nullfile()) dev_null <- grDevices::dev.cur() on.exit(grDevices::dev.off(dev_null), add = TRUE) grobs <- lapply(panels, ggplot2::ggplotGrob) @@ -733,7 +751,7 @@ wrap_gg <- function(x) { #' @export print.talib_gg_chart <- function(x, ...) { if (grDevices::dev.cur() == 1L) { - grDevices::pdf(nullfile()) + grDevices::pdf(.nullfile()) on.exit(grDevices::dev.off(), add = TRUE) } NextMethod() @@ -746,7 +764,7 @@ print.talib_chart <- function(x, ...) { ## avoid Rplots.pdf when no device is open ## (e.g., R CMD check, tests, vignette knit) if (grDevices::dev.cur() == 1L) { - grDevices::pdf(nullfile()) + grDevices::pdf(.nullfile()) on.exit(grDevices::dev.off(), add = TRUE) } diff --git a/R/chart_pattern.R b/R/chart_pattern.R index fdadcb211..ccd645cf5 100644 --- a/R/chart_pattern.R +++ b/R/chart_pattern.R @@ -143,7 +143,9 @@ pattern_gg <- function( bear_data <- data.frame( .chart_pos = chart_pos[idx_bear], y = high[idx_bear] + offset[idx_bear], - label = pattern_name + label = pattern_name, + ## the default flipped in R 4.0; explicit for R >= 3.5 + stringsAsFactors = FALSE ) p <- p + @@ -183,7 +185,9 @@ pattern_gg <- function( } else { low[idx_bull] - offset[idx_bull] }, - label = pattern_name + label = pattern_name, + ## the default flipped in R 4.0; explicit for R >= 3.5 + stringsAsFactors = FALSE ) marker_color <- if (agnostic) { diff --git a/R/helper.R b/R/helper.R index a039e678e..5950039af 100644 --- a/R/helper.R +++ b/R/helper.R @@ -81,17 +81,28 @@ add_idx <- function(x) { ## by chart during initialization idx <- .chart_state()$idx$label - if (!is.null(idx)) { - idx[ - if (is.null(attributes(x)$subset)) { - 1:nrow(x) - } else { - attributes(x)$subset - } - ] - } else { - 1:nrow(x) + if (is.null(idx)) { + return(1:nrow(x)) + } + + subset <- attributes(x)$subset + + if (!is.null(subset)) { + return(idx[subset]) } + + ## a data-override can differ from the chart: surface the + ## mismatch and label the trace with its own rownames + ## instead of silently stamping the chart's dates onto it + if (nrow(x) != length(idx)) { + warning( + "'data' length differs from the chart; using its own labels.", + call. = FALSE + ) + return(rownames(x) %nn% 1:nrow(x)) + } + + idx[1:nrow(x)] } ## apply named overrides to every trace @@ -196,3 +207,18 @@ is.empty.list <- function(x) { is.empty.character <- function(x) { identical(x, character(0)) | grepl("^[[:space:]]*$", x) } + + +as.title_case <- function(x) { + gsub( + pattern = "(^|_)([[:alpha:]])", + replacement = "\\1\\U\\2", + x = x, + perl = TRUE + ) +} + +#' @export +`[[.ta_series` <- function(x, i, ...) { + x[, i] +} diff --git a/R/series.R b/R/series.R index ae62534eb..52ac8f7a7 100644 --- a/R/series.R +++ b/R/series.R @@ -15,9 +15,9 @@ #' Effectively a thin wrapper around [stats::model.frame()]. #' #' @param x Dispatch target: a `formula`, `ggplot`, or `plotly` object. -#' May be omitted by the caller, in which case `default_formula` is +#' May be omitted by the caller, in which case `formula.default` is #' substituted in so dispatch always has a real target. -#' @param default_formula The indicator's default formula +#' @param formula.default The indicator's default formula #' (e.g. `~close`, `~high + low + close`). Used as the fallback for #' `x` and as the minimum-length check in [series.formula()]. #' @param ... Forwarded to the dispatched method - typically `data` @@ -28,43 +28,54 @@ #' @noRd series <- function( x, - default_formula, + formula, ## passed formula + formula.default, ## default formula ... ) { - ## Callers may omit `x` when they want the default formula used - ## wholesale (e.g. indicator(RSI, data = df) with no cols). Populate - ## `x` early so dispatch always has a real target. - if (missing(x)) { - x <- default_formula - } - UseMethod("series", x) } +#' @export +series.default <- function( + x, + formula, + formula.default, + ... +) { + ## classed inputs (zoo, tibble-likes, ...) defer to + ## as.data.frame() for proper method dispatch + series( + x = as.data.frame(x), + formula = formula, + formula.default = formula.default, + ... + ) +} + #' Chart-pipeline entry for ggplot backends. Resolves `formula` against -#' `default_formula` and delegates to [.series_chart_dispatch()]. +#' `formula.default` and delegates to [.series_chart_dispatch()]. #' #' @param x The active `ggplot` chart object dispatched on. -#' @param default_formula The indicator's default formula (e.g. +#' @param formula.default The indicator's default formula (e.g. #' `~close`). #' @param formula Optional explicit column formula; falls back to -#' `default_formula` when missing. +#' `formula.default` when missing. #' @param ... Quoted by the dispatcher and forwarded to #' [stats::model.frame()] - typically `data` and optional `subset`. #' @noRd #' @export series.ggplot <- function( x, - default_formula, formula, + formula.default, ... ) { if (missing(formula)) { - formula <- default_formula + formula <- formula.default } .series_chart_dispatch( x = x, - default_formula = default_formula, + formula.default = formula.default, formula = formula, ... ) @@ -74,26 +85,26 @@ series.ggplot <- function( #' [series.ggplot()]. #' #' @param x The active `plotly` chart object dispatched on. -#' @param default_formula The indicator's default formula (e.g. +#' @param formula.default The indicator's default formula (e.g. #' `~close`). #' @param formula Optional explicit column formula; falls back to -#' `default_formula` when missing. +#' `formula.default` when missing. #' @param ... Quoted by the dispatcher and forwarded to #' [stats::model.frame()] - typically `data` and optional `subset`. #' @noRd #' @export series.plotly <- function( x, - default_formula, formula, + formula.default, ... ) { if (missing(formula)) { - formula <- default_formula + formula <- formula.default } .series_chart_dispatch( x = x, - default_formula = default_formula, + formula.default = formula.default, formula = formula, ... ) @@ -110,7 +121,7 @@ series.plotly <- function( #' on ETH while computing RSI on BTC). #' #' @param x The chart object dispatched on (`ggplot` / `plotly`). -#' @param default_formula The indicator's default formula. +#' @param formula.default The indicator's default formula. #' @param formula Resolved column formula (already defaulted by the #' caller). #' @param ... Caller dots; quoted here so [stats::model.frame()] can @@ -118,8 +129,8 @@ series.plotly <- function( #' @noRd .series_chart_dispatch <- function( x, - default_formula, formula, + formula.default, ... ) { dots_quoted <- as.list( @@ -127,16 +138,37 @@ series.plotly <- function( list(...) ) )[-1L] - dn <- ...names() + ## substitute() captures the argument names alongside the + ## expressions - base::...names() exists only from R 4.1 + dn <- names(dots_quoted) if (length(dots_quoted)) { if (is.null(dn)) { dn <- rep("", length(dots_quoted)) } names(dots_quoted) <- dn + + ## force every argument except 'subset' through its own + ## promise so caller-local objects (data = my_local) + ## resolve in the caller's frame; 'subset' stays quoted + ## for the single model.frame() evaluation downstream + dots_quoted[] <- lapply(seq_along(dots_quoted), function(i) { + if (identical(dn[[i]], "subset")) { + dots_quoted[[i]] + } else { + ...elt(i) + } + }) } else { dots_quoted <- list() } + ## model.frame() falls back to the formula environment for + ## subset symbols that are not columns; re-parent it to the + ## frame that called the wrapper so caller-local objects + ## resolve (three frames up: series method -> wrapper method + ## -> the wrapper's caller) + environment(formula) <- parent.frame(3L) + ## Inject the chart's data only when the caller did NOT pass data ## explicitly. This preserves the per-indicator data override - ## e.g. chart(ETH); indicator(RSI, data = BTC) computes RSI on BTC @@ -156,25 +188,31 @@ series.plotly <- function( dots_quoted$data <- state$x } - output <- as.data.frame( + data_arg <- dots_quoted$data + dots_quoted$data <- NULL + + ## the subset attribute travels on the series result - set + ## once by series.data.frame from what model.frame() kept + as.data.frame( do.call( - series.formula, + series, c( - list(x = formula, default_formula = default_formula), + list( + x = data_arg, + formula = formula, + formula.default = formula.default + ), dots_quoted ), quote = FALSE ) ) - - attr(output, "subset") <- eval(dots_quoted$subset) - output } #' Formula method - the main column-resolution path. #' #' Validates that an explicit `x` covers at least the variables -#' expected by `default_formula`, fast-coerces plain numeric matrices +#' expected by `formula.default`, fast-coerces plain numeric matrices #' via the C helper in `src/dataframe.c`, defers classed inputs (xts, #' zoo, tibble, ...) to [as.data.frame()] for proper method dispatch, #' then builds the model frame. Skips [stats::model.frame()] entirely @@ -182,34 +220,34 @@ series.plotly <- function( #' bare-data path. #' #' @param x A `formula` selecting OHLCV columns (e.g. `~close`, -#' `~high + low + close`). Falls back to `default_formula` when +#' `~high + low + close`). Falls back to `formula.default` when #' missing - the generic populates `x`, but `UseMethod()` re-invokes #' with the original args, so the missing check has to repeat here. -#' @param default_formula The indicator's default formula. Sets the +#' @param formula.default The indicator's default formula. Sets the #' minimum acceptable length for an explicit `x`. #' @param data A data frame, plain numeric matrix, or any object with #' an [as.data.frame()] method. #' @param ... Forwarded to [stats::model.frame()] - typically `subset`. #' @noRd #' @export -series.formula <- function( +series.data.frame <- function( x, - default_formula, - data, + formula, + formula.default, ... ) { - ## UseMethod re-invokes the method with the *original* arguments, - ## so a missing `x` in the generic stays missing here even though - ## the generic assigned it. Re-resolve before touching `x`. - if (missing(x)) { - x <- default_formula + # ## UseMethod re-invokes the method with the *original* arguments, + # ## so a missing `x` in the generic stays missing here even though + # ## the generic assigned it. Re-resolve before touching `x`. + if (missing(formula)) { + formula <- formula.default } ## An explicit formula must cover at least the variables expected by ## the indicator's default. A longer formula is allowed - downstream ## code only consumes what it needs. - formula_length <- length(all.vars(x)) - default_length <- length(all.vars(default_formula)) + formula_length <- length(all.vars(formula)) + default_length <- length(all.vars(formula.default)) assert( x = formula_length >= default_length, @@ -218,47 +256,174 @@ series.formula <- function( paste0("Got length ", formula_length, "."), paste0( "Uses ", - paste0("'", all.vars(default_formula), "'", collapse = ", "), + paste0("'", all.vars(formula.default), "'", collapse = ", "), " by default." ) ) - ## Fast matrix -> data.frame coercion via the C helper in - ## src/dataframe.c. Restricted to *plain* numeric matrices: an - ## explicit class (xts, zoo, tibble, ...) is left to as.data.frame - ## so the dispatch system picks the correct coercion method. - if ( - is.matrix(data) && - is.null(oldClass(data)) && - typeof(data) %in% c("double", "integer") - ) { - data <- map_dfr(data) - } else if (!is.data.frame(data)) { - ## map_dfr only registers methods for plain double / integer - ## matrices, so anything carrying an explicit class (xts, zoo, - ## tibble, ...) or a non-numeric type has to go through - ## as.data.frame so its method-dispatched coercion runs. - data <- as.data.frame(data) - } - assert_column_names( - formula = x, - available_variables = colnames(data) + formula = formula, + available_variables = colnames(x) ) dots_quoted <- as.list(substitute(list(...)))[-1L] if (length(dots_quoted) == 0L) { - output <- data[, all.vars(x), drop = FALSE] + output <- x[, all.vars(formula), drop = FALSE] } else { output <- do.call( stats::model.frame, - c(list(formula = x, data = data), dots_quoted), + c(list(formula = formula, data = x), dots_quoted), quote = FALSE ) - } - attr(output, "subset") <- eval(dots_quoted$subset) + ## the rows model.frame() actually kept - evaluated once, + ## in the data context. Consumers (add_idx, the chart + ## builders) index the chart axis with these positions. + if ("subset" %in% names(dots_quoted)) { + attr(output, "subset") <- match(rownames(output), rownames(x)) + } + } output } + +#' @export +series.matrix <- function( + x, + formula, + formula.default, + ... +) { + ## convert to + ## and pass into series + x <- map_dfr(x) + + series( + x = x, + formula = formula, + formula.default = formula.default + ) +} + +#' @export +series.xts <- function( + x, + formula, + formula.default, + ... +) { + ## reclass 'x' so downstream can + ## can handle the output + class(x) <- c( + class(x), + "ta_series" + ) + + ## fast-track univariate input: a single-column + ## is consumed as-is when the indicator expects a single + ## series, regardless of its column name + if (missing(formula)) { + if (NCOL(x) == 1L && length(all.vars(formula.default)) == 1L) { + return(x) + } + + ## if the formula is not passed + ## it should be replaced by the default + formula <- formula.default + } + + if (...length()) { + warning( + "'...' is passed but is unused for .", + call. = FALSE + ) + } + + ## an explicit formula must cover at least the variables + ## expected by the indicator's default. A longer formula is + ## allowed - downstream code only consumes what it needs. + formula_length <- length(all.vars(formula)) + default_length <- length(all.vars(formula.default)) + + assert( + x = formula_length >= default_length, + call = sys.call(sys.parent()), + paste0("Expected 'cols' length to be ", default_length, "."), + paste0("Got length ", formula_length, "."), + paste0( + "Uses ", + paste0("'", all.vars(formula.default), "'", collapse = ", "), + " by default." + ) + ) + + passed_variables <- all.vars(formula) + available_variables <- colnames(x) + + lowered_passed <- tolower(passed_variables) + lowered_available <- tolower(available_variables) + + ## match matrix: one row per formula variable, one column + ## per column. Exact name matches win over + ## quantmod-style suffix matches (close -> TICKER.Close) so + ## a plain 'Close' column is preferred over 'Adj.Close'; + ## columns are resolved in formula order because the C layer + ## consumes them positionally + exact_hits <- outer( + lowered_passed, + lowered_available, + `==` + ) + + suffix_hits <- outer( + paste0(".", lowered_passed), + lowered_available, + function(suffix, name) endsWith(name, suffix) + ) + + suffix_hits[rowSums(exact_hits) > 0L, ] <- FALSE + + hits <- exact_hits | suffix_hits + matches <- rowSums(hits) + + assert( + x = all(matches > 0L), + call = sys.call(sys.parent()), + paste( + "Expected to find columns", + paste0("'", passed_variables, "'", collapse = ", ") + ), + paste0( + "available columns: ", + paste0("'", available_variables, "'", collapse = ", ") + ) + ) + + assert( + x = all(matches == 1L), + call = sys.call(sys.parent()), + paste( + "Ambiguous columns", + paste0("'", passed_variables[matches > 1L], "'", collapse = ", "), + "." + ), + paste0( + "Matches: ", + paste0( + "'", + available_variables[ + colSums(hits[matches > 1L, , drop = FALSE]) > 0L + ], + "'", + collapse = ", " + ), + "." + ) + ) + + ## the single TRUE per row is the resolved column + identified_columns <- max.col(hits, ties.method = "first") + + x[, identified_columns, drop = FALSE] +} diff --git a/R/ta_ACCBANDS.R b/R/ta_ACCBANDS.R index 8ed41cb75..32cad2c03 100644 --- a/R/ta_ACCBANDS.R +++ b/R/ta_ACCBANDS.R @@ -58,15 +58,15 @@ acceleration_bands.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ acceleration_bands.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ acceleration_bands.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( acceleration_bands.default( x = x, cols = cols, @@ -119,12 +119,38 @@ acceleration_bands.matrix <- function( na.bridge = FALSE, ... ) { - acceleration_bands.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + acceleration_bands.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases acceleration_bands +#' +#' @export +acceleration_bands.xts <- function( + x, + cols, + timePeriod = 20, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + acceleration_bands.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -172,7 +198,7 @@ acceleration_bands.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -274,7 +300,7 @@ acceleration_bands.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_AD.R b/R/ta_AD.R index df8a4f373..b16632b1e 100644 --- a/R/ta_AD.R +++ b/R/ta_AD.R @@ -56,15 +56,15 @@ chaikin_accumulation_distribution_line.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ chaikin_accumulation_distribution_line.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -94,7 +94,7 @@ chaikin_accumulation_distribution_line.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( chaikin_accumulation_distribution_line.default( x = x, cols = cols, @@ -114,11 +114,35 @@ chaikin_accumulation_distribution_line.matrix <- function( na.bridge = FALSE, ... ) { - chaikin_accumulation_distribution_line.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + chaikin_accumulation_distribution_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases chaikin_accumulation_distribution_line +#' +#' @export +chaikin_accumulation_distribution_line.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + chaikin_accumulation_distribution_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -162,7 +186,7 @@ chaikin_accumulation_distribution_line.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) @@ -253,7 +277,7 @@ chaikin_accumulation_distribution_line.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) diff --git a/R/ta_ADOSC.R b/R/ta_ADOSC.R index ab96fde67..4b5e02149 100644 --- a/R/ta_ADOSC.R +++ b/R/ta_ADOSC.R @@ -61,15 +61,15 @@ chaikin_accumulation_distribution_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -85,7 +85,7 @@ chaikin_accumulation_distribution_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -103,7 +103,7 @@ chaikin_accumulation_distribution_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( chaikin_accumulation_distribution_oscillator.default( x = x, cols = cols, @@ -127,13 +127,41 @@ chaikin_accumulation_distribution_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - chaikin_accumulation_distribution_oscillator.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - slowPeriod = slowPeriod, - na.bridge = na.bridge, - ... + as.matrix( + chaikin_accumulation_distribution_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases chaikin_accumulation_distribution_oscillator +#' +#' @export +chaikin_accumulation_distribution_oscillator.xts <- function( + x, + cols, + fastPeriod = 3, + slowPeriod = 10, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + chaikin_accumulation_distribution_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -183,7 +211,7 @@ chaikin_accumulation_distribution_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) @@ -278,7 +306,7 @@ chaikin_accumulation_distribution_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) diff --git a/R/ta_ADX.R b/R/ta_ADX.R index 83af497dc..40c28a2ba 100644 --- a/R/ta_ADX.R +++ b/R/ta_ADX.R @@ -58,15 +58,15 @@ average_directional_movement_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ average_directional_movement_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ average_directional_movement_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( average_directional_movement_index.default( x = x, cols = cols, @@ -119,12 +119,38 @@ average_directional_movement_index.matrix <- function( na.bridge = FALSE, ... ) { - average_directional_movement_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + average_directional_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases average_directional_movement_index +#' +#' @export +average_directional_movement_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + average_directional_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -174,7 +200,7 @@ average_directional_movement_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -277,7 +303,7 @@ average_directional_movement_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_ADXR.R b/R/ta_ADXR.R index df7790c60..3a44b5906 100644 --- a/R/ta_ADXR.R +++ b/R/ta_ADXR.R @@ -58,15 +58,15 @@ average_directional_movement_index_rating.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ average_directional_movement_index_rating.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ average_directional_movement_index_rating.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( average_directional_movement_index_rating.default( x = x, cols = cols, @@ -119,12 +119,38 @@ average_directional_movement_index_rating.matrix <- function( na.bridge = FALSE, ... ) { - average_directional_movement_index_rating.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + average_directional_movement_index_rating.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases average_directional_movement_index_rating +#' +#' @export +average_directional_movement_index_rating.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + average_directional_movement_index_rating.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -174,7 +200,7 @@ average_directional_movement_index_rating.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -277,7 +303,7 @@ average_directional_movement_index_rating.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_APO.R b/R/ta_APO.R index bbb865b61..1f01e1484 100644 --- a/R/ta_APO.R +++ b/R/ta_APO.R @@ -64,15 +64,15 @@ absolute_price_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -86,7 +86,7 @@ absolute_price_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -105,7 +105,7 @@ absolute_price_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( absolute_price_oscillator.default( x = x, cols = cols, @@ -131,14 +131,44 @@ absolute_price_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - absolute_price_oscillator.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - slowPeriod = slowPeriod, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + absolute_price_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases absolute_price_oscillator +#' +#' @export +absolute_price_oscillator.xts <- function( + x, + cols, + fastPeriod = 12, + slowPeriod = 26, + maType = 1, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + absolute_price_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -181,6 +211,10 @@ absolute_price_oscillator.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -195,6 +229,7 @@ absolute_price_oscillator.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -230,7 +265,7 @@ absolute_price_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -334,7 +369,7 @@ absolute_price_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_AROON.R b/R/ta_AROON.R index e9cbb8da1..0ac0aa481 100644 --- a/R/ta_AROON.R +++ b/R/ta_AROON.R @@ -51,15 +51,15 @@ aroon.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -72,7 +72,7 @@ aroon.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -89,7 +89,7 @@ aroon.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( aroon.default( x = x, cols = cols, @@ -111,12 +111,38 @@ aroon.matrix <- function( na.bridge = FALSE, ... ) { - aroon.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + aroon.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases aroon +#' +#' @export +aroon.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + aroon.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -163,7 +189,7 @@ aroon.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -275,7 +301,7 @@ aroon.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_AROONOSC.R b/R/ta_AROONOSC.R index e1c68b01a..87ec327b7 100644 --- a/R/ta_AROONOSC.R +++ b/R/ta_AROONOSC.R @@ -58,15 +58,15 @@ aroon_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -79,7 +79,7 @@ aroon_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -96,7 +96,7 @@ aroon_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( aroon_oscillator.default( x = x, cols = cols, @@ -118,12 +118,38 @@ aroon_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - aroon_oscillator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + aroon_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases aroon_oscillator +#' +#' @export +aroon_oscillator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + aroon_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -170,7 +196,7 @@ aroon_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -268,7 +294,7 @@ aroon_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_ATR.R b/R/ta_ATR.R index f0566f42e..356066903 100644 --- a/R/ta_ATR.R +++ b/R/ta_ATR.R @@ -58,15 +58,15 @@ average_true_range.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ average_true_range.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ average_true_range.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( average_true_range.default( x = x, cols = cols, @@ -119,12 +119,38 @@ average_true_range.matrix <- function( na.bridge = FALSE, ... ) { - average_true_range.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + average_true_range.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases average_true_range +#' +#' @export +average_true_range.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + average_true_range.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -171,7 +197,7 @@ average_true_range.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -264,7 +290,7 @@ average_true_range.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_AVGDEV.R b/R/ta_AVGDEV.R index eefd4249a..206bbef4f 100644 --- a/R/ta_AVGDEV.R +++ b/R/ta_AVGDEV.R @@ -58,15 +58,15 @@ average_deviation.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ average_deviation.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ average_deviation.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( average_deviation.default( x = x, cols = cols, @@ -117,12 +117,38 @@ average_deviation.matrix <- function( na.bridge = FALSE, ... ) { - average_deviation.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + average_deviation.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases average_deviation +#' +#' @export +average_deviation.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + average_deviation.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ average_deviation.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ average_deviation.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } diff --git a/R/ta_AVGPRICE.R b/R/ta_AVGPRICE.R index 17162dc7a..cd7743a7e 100644 --- a/R/ta_AVGPRICE.R +++ b/R/ta_AVGPRICE.R @@ -56,15 +56,15 @@ average_price.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ open + high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ average_price.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -94,7 +94,7 @@ average_price.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( average_price.default( x = x, cols = cols, @@ -114,11 +114,35 @@ average_price.matrix <- function( na.bridge = FALSE, ... ) { - average_price.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + average_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases average_price +#' +#' @export +average_price.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + average_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } diff --git a/R/ta_BBANDS.R b/R/ta_BBANDS.R index f74fc476f..afac0833c 100644 --- a/R/ta_BBANDS.R +++ b/R/ta_BBANDS.R @@ -66,15 +66,15 @@ bollinger_bands.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -89,7 +89,7 @@ bollinger_bands.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -109,7 +109,7 @@ bollinger_bands.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( bollinger_bands.default( x = x, cols = cols, @@ -137,15 +137,47 @@ bollinger_bands.matrix <- function( na.bridge = FALSE, ... ) { - bollinger_bands.default( - x = x, - cols = cols, - timePeriod = timePeriod, - deviationsUp = deviationsUp, - deviationsDown = deviationsDown, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + bollinger_bands.default( + x = x, + cols = cols, + timePeriod = timePeriod, + deviationsUp = deviationsUp, + deviationsDown = deviationsDown, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases bollinger_bands +#' +#' @export +bollinger_bands.xts <- function( + x, + cols, + timePeriod = 20, + deviationsUp = 2, + deviationsDown = 2, + maType = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + bollinger_bands.default( + x = x, + cols = cols, + timePeriod = timePeriod, + deviationsUp = deviationsUp, + deviationsDown = deviationsDown, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -191,6 +223,10 @@ bollinger_bands.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -206,6 +242,7 @@ bollinger_bands.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -243,7 +280,7 @@ bollinger_bands.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -375,7 +412,7 @@ bollinger_bands.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_BETA.R b/R/ta_BETA.R index ad2bf57b9..a6a1da5d3 100644 --- a/R/ta_BETA.R +++ b/R/ta_BETA.R @@ -47,6 +47,23 @@ rolling_beta.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + assert( + x = NCOL(y) == 1L, + call = sys.call(sys.parent()), + "Expected 'y' to be univariate.", + paste0("Got ", NCOL(y), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -63,6 +80,7 @@ rolling_beta.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -97,6 +115,57 @@ rolling_beta.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_beta +#' +#' @export +rolling_beta.xts <- function( + x, + y, + timePeriod = 5, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + assert( + x = NCOL(y) == 1L, + call = sys.call(sys.parent()), + "Expected 'y' to be univariate.", + paste0("Got ", NCOL(y), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_BETA, + as.double(x), + as.double(y), + as.integer(timePeriod), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL BETA_lookback <- rollingBeta_lookback <- rolling_beta_lookback <- function( x, diff --git a/R/ta_BOP.R b/R/ta_BOP.R index 01a6ff1fc..dd38776ff 100644 --- a/R/ta_BOP.R +++ b/R/ta_BOP.R @@ -56,15 +56,15 @@ balance_of_power.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ open + high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ balance_of_power.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -94,7 +94,7 @@ balance_of_power.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( balance_of_power.default( x = x, cols = cols, @@ -114,11 +114,35 @@ balance_of_power.matrix <- function( na.bridge = FALSE, ... ) { - balance_of_power.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + balance_of_power.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases balance_of_power +#' +#' @export +balance_of_power.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + balance_of_power.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -162,7 +186,7 @@ balance_of_power.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -264,7 +288,7 @@ balance_of_power.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CCI.R b/R/ta_CCI.R index 1119c1a35..f2011144b 100644 --- a/R/ta_CCI.R +++ b/R/ta_CCI.R @@ -58,15 +58,15 @@ commodity_channel_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ commodity_channel_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ commodity_channel_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( commodity_channel_index.default( x = x, cols = cols, @@ -119,12 +119,38 @@ commodity_channel_index.matrix <- function( na.bridge = FALSE, ... ) { - commodity_channel_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + commodity_channel_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases commodity_channel_index +#' +#' @export +commodity_channel_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + commodity_channel_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -173,7 +199,7 @@ commodity_channel_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -270,7 +296,7 @@ commodity_channel_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_CDL2CROWS.R b/R/ta_CDL2CROWS.R index 3615e4201..041cecd50 100644 --- a/R/ta_CDL2CROWS.R +++ b/R/ta_CDL2CROWS.R @@ -77,35 +77,33 @@ two_crows.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL2CROWS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL2CROWS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL2CROWS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ two_crows.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( two_crows.default( x = x, cols = cols, @@ -141,14 +139,39 @@ two_crows.matrix <- function( na.bridge = FALSE, ... ) { - two_crows.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + two_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases two_crows +#' +#' @export +two_crows.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + two_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL2CROWS_lookback <- twoCrows_lookback <- two_crows_lookback <- function( x, @@ -186,7 +209,7 @@ two_crows.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ two_crows.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3BLACKCROWS.R b/R/ta_CDL3BLACKCROWS.R index d0c73ace4..e768f5cc7 100644 --- a/R/ta_CDL3BLACKCROWS.R +++ b/R/ta_CDL3BLACKCROWS.R @@ -77,35 +77,33 @@ three_black_crows.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3BLACKCROWS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3BLACKCROWS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3BLACKCROWS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_black_crows.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_black_crows.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_black_crows.matrix <- function( na.bridge = FALSE, ... ) { - three_black_crows.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_black_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_black_crows +#' +#' @export +three_black_crows.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_black_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3BLACKCROWS_lookback <- threeBlackCrows_lookback <- three_black_crows_lookback <- function( x, @@ -186,7 +209,7 @@ three_black_crows.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_black_crows.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3INSIDE.R b/R/ta_CDL3INSIDE.R index da82524b7..01b5be798 100644 --- a/R/ta_CDL3INSIDE.R +++ b/R/ta_CDL3INSIDE.R @@ -77,35 +77,33 @@ three_inside.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3INSIDE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3INSIDE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3INSIDE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_inside.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_inside.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_inside.matrix <- function( na.bridge = FALSE, ... ) { - three_inside.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_inside.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_inside +#' +#' @export +three_inside.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_inside.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3INSIDE_lookback <- threeInside_lookback <- three_inside_lookback <- function( x, @@ -186,7 +209,7 @@ three_inside.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_inside.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3LINESTRIKE.R b/R/ta_CDL3LINESTRIKE.R index e590b4dfd..d8785b4d5 100644 --- a/R/ta_CDL3LINESTRIKE.R +++ b/R/ta_CDL3LINESTRIKE.R @@ -77,35 +77,33 @@ three_line_strike.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3LINESTRIKE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3LINESTRIKE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3LINESTRIKE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_line_strike.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_line_strike.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_line_strike.matrix <- function( na.bridge = FALSE, ... ) { - three_line_strike.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_line_strike.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_line_strike +#' +#' @export +three_line_strike.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_line_strike.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3LINESTRIKE_lookback <- threeLineStrike_lookback <- three_line_strike_lookback <- function( x, @@ -186,7 +209,7 @@ three_line_strike.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_line_strike.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3OUTSIDE.R b/R/ta_CDL3OUTSIDE.R index fc629a2a9..9631570a1 100644 --- a/R/ta_CDL3OUTSIDE.R +++ b/R/ta_CDL3OUTSIDE.R @@ -77,35 +77,33 @@ three_outside.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3OUTSIDE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3OUTSIDE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3OUTSIDE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_outside.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_outside.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_outside.matrix <- function( na.bridge = FALSE, ... ) { - three_outside.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_outside.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_outside +#' +#' @export +three_outside.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_outside.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3OUTSIDE_lookback <- threeOutside_lookback <- three_outside_lookback <- function( x, @@ -186,7 +209,7 @@ three_outside.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_outside.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3STARSINSOUTH.R b/R/ta_CDL3STARSINSOUTH.R index 723b918e5..481ccd6f5 100644 --- a/R/ta_CDL3STARSINSOUTH.R +++ b/R/ta_CDL3STARSINSOUTH.R @@ -77,35 +77,33 @@ three_stars_in_the_south.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3STARSINSOUTH, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3STARSINSOUTH, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3STARSINSOUTH" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_stars_in_the_south.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_stars_in_the_south.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_stars_in_the_south.matrix <- function( na.bridge = FALSE, ... ) { - three_stars_in_the_south.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_stars_in_the_south.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_stars_in_the_south +#' +#' @export +three_stars_in_the_south.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_stars_in_the_south.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3STARSINSOUTH_lookback <- threeStarsInTheSouth_lookback <- three_stars_in_the_south_lookback <- function( x, @@ -186,7 +209,7 @@ three_stars_in_the_south.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_stars_in_the_south.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDL3WHITESOLDIERS.R b/R/ta_CDL3WHITESOLDIERS.R index 9e30ca422..04b97f4bf 100644 --- a/R/ta_CDL3WHITESOLDIERS.R +++ b/R/ta_CDL3WHITESOLDIERS.R @@ -77,35 +77,33 @@ three_white_soldiers.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDL3WHITESOLDIERS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDL3WHITESOLDIERS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDL3WHITESOLDIERS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_white_soldiers.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_white_soldiers.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_white_soldiers.matrix <- function( na.bridge = FALSE, ... ) { - three_white_soldiers.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_white_soldiers.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_white_soldiers +#' +#' @export +three_white_soldiers.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_white_soldiers.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDL3WHITESOLDIERS_lookback <- threeWhiteSoldiers_lookback <- three_white_soldiers_lookback <- function( x, @@ -186,7 +209,7 @@ three_white_soldiers.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_white_soldiers.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLABANDONEDBABY.R b/R/ta_CDLABANDONEDBABY.R index 387eae1c4..7774f8f28 100644 --- a/R/ta_CDLABANDONEDBABY.R +++ b/R/ta_CDLABANDONEDBABY.R @@ -79,36 +79,34 @@ abandoned_baby.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLABANDONEDBABY, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLABANDONEDBABY, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLABANDONEDBABY" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ abandoned_baby.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( abandoned_baby.default( x = x, cols = cols, @@ -147,15 +145,42 @@ abandoned_baby.matrix <- function( na.bridge = FALSE, ... ) { - abandoned_baby.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + abandoned_baby.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases abandoned_baby +#' +#' @export +abandoned_baby.xts <- function( + x, + cols, + penetration = 0.3, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + abandoned_baby.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLABANDONEDBABY_lookback <- abandonedBaby_lookback <- abandoned_baby_lookback <- function( x, @@ -196,7 +221,7 @@ abandoned_baby.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ abandoned_baby.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLADVANCEBLOCK.R b/R/ta_CDLADVANCEBLOCK.R index 7930fd926..cf0a27b2f 100644 --- a/R/ta_CDLADVANCEBLOCK.R +++ b/R/ta_CDLADVANCEBLOCK.R @@ -77,35 +77,33 @@ advance_block.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLADVANCEBLOCK, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLADVANCEBLOCK, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLADVANCEBLOCK" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ advance_block.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( advance_block.default( x = x, cols = cols, @@ -141,14 +139,39 @@ advance_block.matrix <- function( na.bridge = FALSE, ... ) { - advance_block.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + advance_block.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases advance_block +#' +#' @export +advance_block.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + advance_block.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLADVANCEBLOCK_lookback <- advanceBlock_lookback <- advance_block_lookback <- function( x, @@ -186,7 +209,7 @@ advance_block.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ advance_block.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLBELTHOLD.R b/R/ta_CDLBELTHOLD.R index 774588470..8e9d7ab8c 100644 --- a/R/ta_CDLBELTHOLD.R +++ b/R/ta_CDLBELTHOLD.R @@ -77,35 +77,33 @@ belt_hold.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLBELTHOLD, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLBELTHOLD, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLBELTHOLD" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ belt_hold.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( belt_hold.default( x = x, cols = cols, @@ -141,14 +139,39 @@ belt_hold.matrix <- function( na.bridge = FALSE, ... ) { - belt_hold.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + belt_hold.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases belt_hold +#' +#' @export +belt_hold.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + belt_hold.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLBELTHOLD_lookback <- beltHold_lookback <- belt_hold_lookback <- function( x, @@ -186,7 +209,7 @@ belt_hold.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ belt_hold.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLBREAKAWAY.R b/R/ta_CDLBREAKAWAY.R index 3c2bc9b19..e2a6d84f1 100644 --- a/R/ta_CDLBREAKAWAY.R +++ b/R/ta_CDLBREAKAWAY.R @@ -77,35 +77,33 @@ break_away.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLBREAKAWAY, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLBREAKAWAY, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLBREAKAWAY" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ break_away.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( break_away.default( x = x, cols = cols, @@ -141,14 +139,39 @@ break_away.matrix <- function( na.bridge = FALSE, ... ) { - break_away.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + break_away.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases break_away +#' +#' @export +break_away.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + break_away.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLBREAKAWAY_lookback <- breakAway_lookback <- break_away_lookback <- function( x, @@ -186,7 +209,7 @@ break_away.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ break_away.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLCLOSINGMARUBOZU.R b/R/ta_CDLCLOSINGMARUBOZU.R index af68e5998..b4934ab82 100644 --- a/R/ta_CDLCLOSINGMARUBOZU.R +++ b/R/ta_CDLCLOSINGMARUBOZU.R @@ -77,35 +77,33 @@ closing_marubozu.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLCLOSINGMARUBOZU, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLCLOSINGMARUBOZU, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLCLOSINGMARUBOZU" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ closing_marubozu.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( closing_marubozu.default( x = x, cols = cols, @@ -141,14 +139,39 @@ closing_marubozu.matrix <- function( na.bridge = FALSE, ... ) { - closing_marubozu.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + closing_marubozu.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases closing_marubozu +#' +#' @export +closing_marubozu.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + closing_marubozu.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLCLOSINGMARUBOZU_lookback <- closingMarubozu_lookback <- closing_marubozu_lookback <- function( x, @@ -186,7 +209,7 @@ closing_marubozu.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ closing_marubozu.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLCONCEALBABYSWALL.R b/R/ta_CDLCONCEALBABYSWALL.R index 52100f9bf..230b40268 100644 --- a/R/ta_CDLCONCEALBABYSWALL.R +++ b/R/ta_CDLCONCEALBABYSWALL.R @@ -77,35 +77,33 @@ concealing_baby_swallow.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLCONCEALBABYSWALL, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLCONCEALBABYSWALL, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLCONCEALBABYSWALL" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ concealing_baby_swallow.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( concealing_baby_swallow.default( x = x, cols = cols, @@ -141,14 +139,39 @@ concealing_baby_swallow.matrix <- function( na.bridge = FALSE, ... ) { - concealing_baby_swallow.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + concealing_baby_swallow.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases concealing_baby_swallow +#' +#' @export +concealing_baby_swallow.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + concealing_baby_swallow.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLCONCEALBABYSWALL_lookback <- concealingBabySwallow_lookback <- concealing_baby_swallow_lookback <- function( x, @@ -186,7 +209,7 @@ concealing_baby_swallow.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ concealing_baby_swallow.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLCOUNTERATTACK.R b/R/ta_CDLCOUNTERATTACK.R index 3f14a1af8..1ae7e62a7 100644 --- a/R/ta_CDLCOUNTERATTACK.R +++ b/R/ta_CDLCOUNTERATTACK.R @@ -77,35 +77,33 @@ counter_attack.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLCOUNTERATTACK, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLCOUNTERATTACK, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLCOUNTERATTACK" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ counter_attack.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( counter_attack.default( x = x, cols = cols, @@ -141,14 +139,39 @@ counter_attack.matrix <- function( na.bridge = FALSE, ... ) { - counter_attack.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + counter_attack.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases counter_attack +#' +#' @export +counter_attack.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + counter_attack.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLCOUNTERATTACK_lookback <- counterAttack_lookback <- counter_attack_lookback <- function( x, @@ -186,7 +209,7 @@ counter_attack.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ counter_attack.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLDARKCLOUDCOVER.R b/R/ta_CDLDARKCLOUDCOVER.R index da42c6f96..3642e3abf 100644 --- a/R/ta_CDLDARKCLOUDCOVER.R +++ b/R/ta_CDLDARKCLOUDCOVER.R @@ -79,36 +79,34 @@ dark_cloud_cover.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLDARKCLOUDCOVER, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLDARKCLOUDCOVER, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLDARKCLOUDCOVER" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ dark_cloud_cover.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( dark_cloud_cover.default( x = x, cols = cols, @@ -147,15 +145,42 @@ dark_cloud_cover.matrix <- function( na.bridge = FALSE, ... ) { - dark_cloud_cover.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + dark_cloud_cover.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases dark_cloud_cover +#' +#' @export +dark_cloud_cover.xts <- function( + x, + cols, + penetration = 0.5, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + dark_cloud_cover.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLDARKCLOUDCOVER_lookback <- darkCloudCover_lookback <- dark_cloud_cover_lookback <- function( x, @@ -196,7 +221,7 @@ dark_cloud_cover.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ dark_cloud_cover.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLDOJI.R b/R/ta_CDLDOJI.R index bec111837..822363ed6 100644 --- a/R/ta_CDLDOJI.R +++ b/R/ta_CDLDOJI.R @@ -70,35 +70,33 @@ doji.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLDOJI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLDOJI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLDOJI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ doji.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( doji.default( x = x, cols = cols, @@ -134,14 +132,39 @@ doji.matrix <- function( na.bridge = FALSE, ... ) { - doji.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases doji +#' +#' @export +doji.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLDOJI_lookback <- doji_lookback <- function( x, @@ -179,7 +202,7 @@ doji.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ doji.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLDOJISTAR.R b/R/ta_CDLDOJISTAR.R index d9216409b..5a90b6ff9 100644 --- a/R/ta_CDLDOJISTAR.R +++ b/R/ta_CDLDOJISTAR.R @@ -77,35 +77,33 @@ doji_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLDOJISTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLDOJISTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLDOJISTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ doji_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( doji_star.default( x = x, cols = cols, @@ -141,14 +139,39 @@ doji_star.matrix <- function( na.bridge = FALSE, ... ) { - doji_star.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + doji_star.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases doji_star +#' +#' @export +doji_star.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + doji_star.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLDOJISTAR_lookback <- dojiStar_lookback <- doji_star_lookback <- function( x, @@ -186,7 +209,7 @@ doji_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ doji_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLDRAGONFLYDOJI.R b/R/ta_CDLDRAGONFLYDOJI.R index 9e7bbb2f2..7be22b576 100644 --- a/R/ta_CDLDRAGONFLYDOJI.R +++ b/R/ta_CDLDRAGONFLYDOJI.R @@ -77,35 +77,33 @@ dragonfly_doji.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLDRAGONFLYDOJI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLDRAGONFLYDOJI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLDRAGONFLYDOJI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ dragonfly_doji.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( dragonfly_doji.default( x = x, cols = cols, @@ -141,14 +139,39 @@ dragonfly_doji.matrix <- function( na.bridge = FALSE, ... ) { - dragonfly_doji.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + dragonfly_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases dragonfly_doji +#' +#' @export +dragonfly_doji.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + dragonfly_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLDRAGONFLYDOJI_lookback <- dragonflyDoji_lookback <- dragonfly_doji_lookback <- function( x, @@ -186,7 +209,7 @@ dragonfly_doji.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ dragonfly_doji.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLENGULFING.R b/R/ta_CDLENGULFING.R index ec0a2d952..cb9005901 100644 --- a/R/ta_CDLENGULFING.R +++ b/R/ta_CDLENGULFING.R @@ -70,35 +70,33 @@ engulfing.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLENGULFING, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLENGULFING, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLENGULFING" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ engulfing.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( engulfing.default( x = x, cols = cols, @@ -134,14 +132,39 @@ engulfing.matrix <- function( na.bridge = FALSE, ... ) { - engulfing.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + engulfing.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases engulfing +#' +#' @export +engulfing.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + engulfing.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLENGULFING_lookback <- engulfing_lookback <- function( x, @@ -179,7 +202,7 @@ engulfing.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ engulfing.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLEVENINGDOJISTAR.R b/R/ta_CDLEVENINGDOJISTAR.R index ac78692f3..af912b5a4 100644 --- a/R/ta_CDLEVENINGDOJISTAR.R +++ b/R/ta_CDLEVENINGDOJISTAR.R @@ -79,36 +79,34 @@ evening_doji_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLEVENINGDOJISTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLEVENINGDOJISTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLEVENINGDOJISTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ evening_doji_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( evening_doji_star.default( x = x, cols = cols, @@ -147,15 +145,42 @@ evening_doji_star.matrix <- function( na.bridge = FALSE, ... ) { - evening_doji_star.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + evening_doji_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases evening_doji_star +#' +#' @export +evening_doji_star.xts <- function( + x, + cols, + penetration = 0.3, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + evening_doji_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLEVENINGDOJISTAR_lookback <- eveningDojiStar_lookback <- evening_doji_star_lookback <- function( x, @@ -196,7 +221,7 @@ evening_doji_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ evening_doji_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLEVENINGSTAR.R b/R/ta_CDLEVENINGSTAR.R index 125d85543..6b66a5e45 100644 --- a/R/ta_CDLEVENINGSTAR.R +++ b/R/ta_CDLEVENINGSTAR.R @@ -79,36 +79,34 @@ evening_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLEVENINGSTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLEVENINGSTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLEVENINGSTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ evening_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( evening_star.default( x = x, cols = cols, @@ -147,15 +145,42 @@ evening_star.matrix <- function( na.bridge = FALSE, ... ) { - evening_star.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + evening_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases evening_star +#' +#' @export +evening_star.xts <- function( + x, + cols, + penetration = 0.3, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + evening_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLEVENINGSTAR_lookback <- eveningStar_lookback <- evening_star_lookback <- function( x, @@ -196,7 +221,7 @@ evening_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ evening_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLGAPSIDESIDEWHITE.R b/R/ta_CDLGAPSIDESIDEWHITE.R index de5e8f8c2..ead58bc7d 100644 --- a/R/ta_CDLGAPSIDESIDEWHITE.R +++ b/R/ta_CDLGAPSIDESIDEWHITE.R @@ -77,35 +77,33 @@ gaps_side_white.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLGAPSIDESIDEWHITE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLGAPSIDESIDEWHITE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLGAPSIDESIDEWHITE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ gaps_side_white.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( gaps_side_white.default( x = x, cols = cols, @@ -141,14 +139,39 @@ gaps_side_white.matrix <- function( na.bridge = FALSE, ... ) { - gaps_side_white.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + gaps_side_white.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases gaps_side_white +#' +#' @export +gaps_side_white.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + gaps_side_white.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLGAPSIDESIDEWHITE_lookback <- gapsSideWhite_lookback <- gaps_side_white_lookback <- function( x, @@ -186,7 +209,7 @@ gaps_side_white.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ gaps_side_white.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLGRAVESTONEDOJI.R b/R/ta_CDLGRAVESTONEDOJI.R index a1a8e6b70..3be0fba9f 100644 --- a/R/ta_CDLGRAVESTONEDOJI.R +++ b/R/ta_CDLGRAVESTONEDOJI.R @@ -77,35 +77,33 @@ gravestone_doji.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLGRAVESTONEDOJI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLGRAVESTONEDOJI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLGRAVESTONEDOJI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ gravestone_doji.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( gravestone_doji.default( x = x, cols = cols, @@ -141,14 +139,39 @@ gravestone_doji.matrix <- function( na.bridge = FALSE, ... ) { - gravestone_doji.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + gravestone_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases gravestone_doji +#' +#' @export +gravestone_doji.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + gravestone_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLGRAVESTONEDOJI_lookback <- gravestoneDoji_lookback <- gravestone_doji_lookback <- function( x, @@ -186,7 +209,7 @@ gravestone_doji.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ gravestone_doji.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHAMMER.R b/R/ta_CDLHAMMER.R index b27203f87..89bc13c06 100644 --- a/R/ta_CDLHAMMER.R +++ b/R/ta_CDLHAMMER.R @@ -70,35 +70,33 @@ hammer.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHAMMER, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHAMMER, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHAMMER" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ hammer.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( hammer.default( x = x, cols = cols, @@ -134,14 +132,39 @@ hammer.matrix <- function( na.bridge = FALSE, ... ) { - hammer.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + hammer.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases hammer +#' +#' @export +hammer.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + hammer.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHAMMER_lookback <- hammer_lookback <- function( x, @@ -179,7 +202,7 @@ hammer.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ hammer.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHANGINGMAN.R b/R/ta_CDLHANGINGMAN.R index fcfeb18a9..1fabca8df 100644 --- a/R/ta_CDLHANGINGMAN.R +++ b/R/ta_CDLHANGINGMAN.R @@ -77,35 +77,33 @@ hanging_man.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHANGINGMAN, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHANGINGMAN, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHANGINGMAN" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ hanging_man.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( hanging_man.default( x = x, cols = cols, @@ -141,14 +139,39 @@ hanging_man.matrix <- function( na.bridge = FALSE, ... ) { - hanging_man.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + hanging_man.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases hanging_man +#' +#' @export +hanging_man.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + hanging_man.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHANGINGMAN_lookback <- hangingMan_lookback <- hanging_man_lookback <- function( x, @@ -186,7 +209,7 @@ hanging_man.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ hanging_man.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHARAMI.R b/R/ta_CDLHARAMI.R index 47ea7b55c..7eaa4db61 100644 --- a/R/ta_CDLHARAMI.R +++ b/R/ta_CDLHARAMI.R @@ -70,35 +70,33 @@ harami.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHARAMI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHARAMI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHARAMI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ harami.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( harami.default( x = x, cols = cols, @@ -134,14 +132,39 @@ harami.matrix <- function( na.bridge = FALSE, ... ) { - harami.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + harami.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases harami +#' +#' @export +harami.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + harami.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHARAMI_lookback <- harami_lookback <- function( x, @@ -179,7 +202,7 @@ harami.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ harami.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHARAMICROSS.R b/R/ta_CDLHARAMICROSS.R index 2881eee1c..02d501340 100644 --- a/R/ta_CDLHARAMICROSS.R +++ b/R/ta_CDLHARAMICROSS.R @@ -77,35 +77,33 @@ harami_cross.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHARAMICROSS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHARAMICROSS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHARAMICROSS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ harami_cross.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( harami_cross.default( x = x, cols = cols, @@ -141,14 +139,39 @@ harami_cross.matrix <- function( na.bridge = FALSE, ... ) { - harami_cross.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + harami_cross.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases harami_cross +#' +#' @export +harami_cross.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + harami_cross.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHARAMICROSS_lookback <- haramiCross_lookback <- harami_cross_lookback <- function( x, @@ -186,7 +209,7 @@ harami_cross.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ harami_cross.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHIGHWAVE.R b/R/ta_CDLHIGHWAVE.R index ad60c5929..234665571 100644 --- a/R/ta_CDLHIGHWAVE.R +++ b/R/ta_CDLHIGHWAVE.R @@ -77,35 +77,33 @@ high_wave.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHIGHWAVE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHIGHWAVE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHIGHWAVE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ high_wave.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( high_wave.default( x = x, cols = cols, @@ -141,14 +139,39 @@ high_wave.matrix <- function( na.bridge = FALSE, ... ) { - high_wave.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + high_wave.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases high_wave +#' +#' @export +high_wave.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + high_wave.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHIGHWAVE_lookback <- highWave_lookback <- high_wave_lookback <- function( x, @@ -186,7 +209,7 @@ high_wave.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ high_wave.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHIKKAKE.R b/R/ta_CDLHIKKAKE.R index 8084cb4a3..f7889ab37 100644 --- a/R/ta_CDLHIKKAKE.R +++ b/R/ta_CDLHIKKAKE.R @@ -70,35 +70,33 @@ hikakke.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHIKKAKE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHIKKAKE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHIKKAKE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ hikakke.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( hikakke.default( x = x, cols = cols, @@ -134,14 +132,39 @@ hikakke.matrix <- function( na.bridge = FALSE, ... ) { - hikakke.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + hikakke.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases hikakke +#' +#' @export +hikakke.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + hikakke.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHIKKAKE_lookback <- hikakke_lookback <- function( x, @@ -179,7 +202,7 @@ hikakke.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ hikakke.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHIKKAKEMOD.R b/R/ta_CDLHIKKAKEMOD.R index 11b6bab91..8aff4780a 100644 --- a/R/ta_CDLHIKKAKEMOD.R +++ b/R/ta_CDLHIKKAKEMOD.R @@ -77,35 +77,33 @@ hikakke_mod.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHIKKAKEMOD, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHIKKAKEMOD, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHIKKAKEMOD" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ hikakke_mod.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( hikakke_mod.default( x = x, cols = cols, @@ -141,14 +139,39 @@ hikakke_mod.matrix <- function( na.bridge = FALSE, ... ) { - hikakke_mod.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + hikakke_mod.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases hikakke_mod +#' +#' @export +hikakke_mod.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + hikakke_mod.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHIKKAKEMOD_lookback <- hikakkeMod_lookback <- hikakke_mod_lookback <- function( x, @@ -186,7 +209,7 @@ hikakke_mod.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ hikakke_mod.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLHOMINGPIGEON.R b/R/ta_CDLHOMINGPIGEON.R index fba92b1ea..95087e229 100644 --- a/R/ta_CDLHOMINGPIGEON.R +++ b/R/ta_CDLHOMINGPIGEON.R @@ -77,35 +77,33 @@ homing_pigeon.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLHOMINGPIGEON, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLHOMINGPIGEON, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLHOMINGPIGEON" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ homing_pigeon.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( homing_pigeon.default( x = x, cols = cols, @@ -141,14 +139,39 @@ homing_pigeon.matrix <- function( na.bridge = FALSE, ... ) { - homing_pigeon.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + homing_pigeon.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases homing_pigeon +#' +#' @export +homing_pigeon.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + homing_pigeon.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLHOMINGPIGEON_lookback <- homingPigeon_lookback <- homing_pigeon_lookback <- function( x, @@ -186,7 +209,7 @@ homing_pigeon.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ homing_pigeon.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLIDENTICAL3CROWS.R b/R/ta_CDLIDENTICAL3CROWS.R index 256dc1eb9..4d8da4797 100644 --- a/R/ta_CDLIDENTICAL3CROWS.R +++ b/R/ta_CDLIDENTICAL3CROWS.R @@ -77,35 +77,33 @@ three_identical_crows.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLIDENTICAL3CROWS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLIDENTICAL3CROWS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLIDENTICAL3CROWS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ three_identical_crows.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( three_identical_crows.default( x = x, cols = cols, @@ -141,14 +139,39 @@ three_identical_crows.matrix <- function( na.bridge = FALSE, ... ) { - three_identical_crows.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + three_identical_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases three_identical_crows +#' +#' @export +three_identical_crows.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + three_identical_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLIDENTICAL3CROWS_lookback <- threeIdenticalCrows_lookback <- three_identical_crows_lookback <- function( x, @@ -186,7 +209,7 @@ three_identical_crows.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ three_identical_crows.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLINNECK.R b/R/ta_CDLINNECK.R index aa9398bd4..5b2b777d1 100644 --- a/R/ta_CDLINNECK.R +++ b/R/ta_CDLINNECK.R @@ -77,35 +77,33 @@ in_neck.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLINNECK, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLINNECK, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLINNECK" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ in_neck.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( in_neck.default( x = x, cols = cols, @@ -141,14 +139,39 @@ in_neck.matrix <- function( na.bridge = FALSE, ... ) { - in_neck.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + in_neck.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases in_neck +#' +#' @export +in_neck.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + in_neck.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLINNECK_lookback <- inNeck_lookback <- in_neck_lookback <- function( x, @@ -186,7 +209,7 @@ in_neck.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ in_neck.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLINVERTEDHAMMER.R b/R/ta_CDLINVERTEDHAMMER.R index a55211985..be02d8c1f 100644 --- a/R/ta_CDLINVERTEDHAMMER.R +++ b/R/ta_CDLINVERTEDHAMMER.R @@ -77,35 +77,33 @@ inverted_hammer.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLINVERTEDHAMMER, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLINVERTEDHAMMER, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLINVERTEDHAMMER" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ inverted_hammer.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( inverted_hammer.default( x = x, cols = cols, @@ -141,14 +139,39 @@ inverted_hammer.matrix <- function( na.bridge = FALSE, ... ) { - inverted_hammer.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + inverted_hammer.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases inverted_hammer +#' +#' @export +inverted_hammer.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + inverted_hammer.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLINVERTEDHAMMER_lookback <- invertedHammer_lookback <- inverted_hammer_lookback <- function( x, @@ -186,7 +209,7 @@ inverted_hammer.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ inverted_hammer.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLKICKING.R b/R/ta_CDLKICKING.R index 320620fe1..3b01d6a6a 100644 --- a/R/ta_CDLKICKING.R +++ b/R/ta_CDLKICKING.R @@ -70,35 +70,33 @@ kicking.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLKICKING, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLKICKING, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLKICKING" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ kicking.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( kicking.default( x = x, cols = cols, @@ -134,14 +132,39 @@ kicking.matrix <- function( na.bridge = FALSE, ... ) { - kicking.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + kicking.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases kicking +#' +#' @export +kicking.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + kicking.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLKICKING_lookback <- kicking_lookback <- function( x, @@ -179,7 +202,7 @@ kicking.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ kicking.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLKICKINGBYLENGTH.R b/R/ta_CDLKICKINGBYLENGTH.R index 4fa625ff7..d41d15238 100644 --- a/R/ta_CDLKICKINGBYLENGTH.R +++ b/R/ta_CDLKICKINGBYLENGTH.R @@ -77,35 +77,33 @@ kicking_baby_length.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLKICKINGBYLENGTH, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLKICKINGBYLENGTH, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLKICKINGBYLENGTH" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ kicking_baby_length.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( kicking_baby_length.default( x = x, cols = cols, @@ -141,14 +139,39 @@ kicking_baby_length.matrix <- function( na.bridge = FALSE, ... ) { - kicking_baby_length.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + kicking_baby_length.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases kicking_baby_length +#' +#' @export +kicking_baby_length.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + kicking_baby_length.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLKICKINGBYLENGTH_lookback <- kickingBabyLength_lookback <- kicking_baby_length_lookback <- function( x, @@ -186,7 +209,7 @@ kicking_baby_length.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ kicking_baby_length.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLLADDERBOTTOM.R b/R/ta_CDLLADDERBOTTOM.R index 51fc9e3e9..6bd060d71 100644 --- a/R/ta_CDLLADDERBOTTOM.R +++ b/R/ta_CDLLADDERBOTTOM.R @@ -77,35 +77,33 @@ ladder_bottom.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLLADDERBOTTOM, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLLADDERBOTTOM, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLLADDERBOTTOM" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ ladder_bottom.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ladder_bottom.default( x = x, cols = cols, @@ -141,14 +139,39 @@ ladder_bottom.matrix <- function( na.bridge = FALSE, ... ) { - ladder_bottom.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + ladder_bottom.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases ladder_bottom +#' +#' @export +ladder_bottom.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + ladder_bottom.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLLADDERBOTTOM_lookback <- ladderBottom_lookback <- ladder_bottom_lookback <- function( x, @@ -186,7 +209,7 @@ ladder_bottom.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ ladder_bottom.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLLONGLEGGEDDOJI.R b/R/ta_CDLLONGLEGGEDDOJI.R index 4084282b2..46662a3a6 100644 --- a/R/ta_CDLLONGLEGGEDDOJI.R +++ b/R/ta_CDLLONGLEGGEDDOJI.R @@ -77,35 +77,33 @@ long_legged_doji.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLLONGLEGGEDDOJI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLLONGLEGGEDDOJI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLLONGLEGGEDDOJI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ long_legged_doji.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( long_legged_doji.default( x = x, cols = cols, @@ -141,14 +139,39 @@ long_legged_doji.matrix <- function( na.bridge = FALSE, ... ) { - long_legged_doji.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + long_legged_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases long_legged_doji +#' +#' @export +long_legged_doji.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + long_legged_doji.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLLONGLEGGEDDOJI_lookback <- longLeggedDoji_lookback <- long_legged_doji_lookback <- function( x, @@ -186,7 +209,7 @@ long_legged_doji.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ long_legged_doji.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLLONGLINE.R b/R/ta_CDLLONGLINE.R index 59d24e9b2..00e59f270 100644 --- a/R/ta_CDLLONGLINE.R +++ b/R/ta_CDLLONGLINE.R @@ -77,35 +77,33 @@ long_line.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLLONGLINE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLLONGLINE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLLONGLINE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ long_line.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( long_line.default( x = x, cols = cols, @@ -141,14 +139,39 @@ long_line.matrix <- function( na.bridge = FALSE, ... ) { - long_line.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + long_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases long_line +#' +#' @export +long_line.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + long_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLLONGLINE_lookback <- longLine_lookback <- long_line_lookback <- function( x, @@ -186,7 +209,7 @@ long_line.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ long_line.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLMARUBOZU.R b/R/ta_CDLMARUBOZU.R index ed540a839..3061b07c9 100644 --- a/R/ta_CDLMARUBOZU.R +++ b/R/ta_CDLMARUBOZU.R @@ -70,35 +70,33 @@ marubozu.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLMARUBOZU, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLMARUBOZU, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLMARUBOZU" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ marubozu.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( marubozu.default( x = x, cols = cols, @@ -134,14 +132,39 @@ marubozu.matrix <- function( na.bridge = FALSE, ... ) { - marubozu.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + marubozu.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases marubozu +#' +#' @export +marubozu.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + marubozu.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLMARUBOZU_lookback <- marubozu_lookback <- function( x, @@ -179,7 +202,7 @@ marubozu.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ marubozu.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLMATCHINGLOW.R b/R/ta_CDLMATCHINGLOW.R index b55e7cb94..585d9d479 100644 --- a/R/ta_CDLMATCHINGLOW.R +++ b/R/ta_CDLMATCHINGLOW.R @@ -77,35 +77,33 @@ matching_low.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLMATCHINGLOW, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLMATCHINGLOW, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLMATCHINGLOW" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ matching_low.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( matching_low.default( x = x, cols = cols, @@ -141,14 +139,39 @@ matching_low.matrix <- function( na.bridge = FALSE, ... ) { - matching_low.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + matching_low.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases matching_low +#' +#' @export +matching_low.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + matching_low.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLMATCHINGLOW_lookback <- matchingLow_lookback <- matching_low_lookback <- function( x, @@ -186,7 +209,7 @@ matching_low.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ matching_low.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLMATHOLD.R b/R/ta_CDLMATHOLD.R index 180fd8a4c..04fcb0fb5 100644 --- a/R/ta_CDLMATHOLD.R +++ b/R/ta_CDLMATHOLD.R @@ -79,36 +79,34 @@ mat_hold.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLMATHOLD, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLMATHOLD, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLMATHOLD" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ mat_hold.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( mat_hold.default( x = x, cols = cols, @@ -147,15 +145,42 @@ mat_hold.matrix <- function( na.bridge = FALSE, ... ) { - mat_hold.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + mat_hold.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases mat_hold +#' +#' @export +mat_hold.xts <- function( + x, + cols, + penetration = 0.5, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + mat_hold.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLMATHOLD_lookback <- matHold_lookback <- mat_hold_lookback <- function( x, @@ -196,7 +221,7 @@ mat_hold.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ mat_hold.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLMORNINGDOJISTAR.R b/R/ta_CDLMORNINGDOJISTAR.R index ef9075fb7..2bc40b3eb 100644 --- a/R/ta_CDLMORNINGDOJISTAR.R +++ b/R/ta_CDLMORNINGDOJISTAR.R @@ -79,36 +79,34 @@ morning_doji_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLMORNINGDOJISTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLMORNINGDOJISTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLMORNINGDOJISTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ morning_doji_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( morning_doji_star.default( x = x, cols = cols, @@ -147,15 +145,42 @@ morning_doji_star.matrix <- function( na.bridge = FALSE, ... ) { - morning_doji_star.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + morning_doji_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases morning_doji_star +#' +#' @export +morning_doji_star.xts <- function( + x, + cols, + penetration = 0.3, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + morning_doji_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLMORNINGDOJISTAR_lookback <- morningDojiStar_lookback <- morning_doji_star_lookback <- function( x, @@ -196,7 +221,7 @@ morning_doji_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ morning_doji_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLMORNINGSTAR.R b/R/ta_CDLMORNINGSTAR.R index 94dbf01f7..8ce6e2a56 100644 --- a/R/ta_CDLMORNINGSTAR.R +++ b/R/ta_CDLMORNINGSTAR.R @@ -79,36 +79,34 @@ morning_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLMORNINGSTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - as.double(penetration), - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLMORNINGSTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + as.double(penetration), + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLMORNINGSTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -125,7 +123,7 @@ morning_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( morning_star.default( x = x, cols = cols, @@ -147,15 +145,42 @@ morning_star.matrix <- function( na.bridge = FALSE, ... ) { - morning_star.default( - x = x, - cols = cols, - penetration = penetration, - na.bridge = na.bridge, - ... + as.matrix( + morning_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases morning_star +#' +#' @export +morning_star.xts <- function( + x, + cols, + penetration = 0.3, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + morning_star.default( + x = x, + cols = cols, + penetration = penetration, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLMORNINGSTAR_lookback <- morningStar_lookback <- morning_star_lookback <- function( x, @@ -196,7 +221,7 @@ morning_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -256,7 +281,7 @@ morning_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLONNECK.R b/R/ta_CDLONNECK.R index 1158f827d..1f6c60444 100644 --- a/R/ta_CDLONNECK.R +++ b/R/ta_CDLONNECK.R @@ -77,35 +77,33 @@ on_neck.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLONNECK, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLONNECK, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLONNECK" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ on_neck.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( on_neck.default( x = x, cols = cols, @@ -141,14 +139,39 @@ on_neck.matrix <- function( na.bridge = FALSE, ... ) { - on_neck.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + on_neck.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases on_neck +#' +#' @export +on_neck.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + on_neck.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLONNECK_lookback <- onNeck_lookback <- on_neck_lookback <- function( x, @@ -186,7 +209,7 @@ on_neck.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ on_neck.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLPIERCING.R b/R/ta_CDLPIERCING.R index efa7e433f..c7396581a 100644 --- a/R/ta_CDLPIERCING.R +++ b/R/ta_CDLPIERCING.R @@ -70,35 +70,33 @@ piercing.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLPIERCING, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLPIERCING, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLPIERCING" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ piercing.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( piercing.default( x = x, cols = cols, @@ -134,14 +132,39 @@ piercing.matrix <- function( na.bridge = FALSE, ... ) { - piercing.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + piercing.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases piercing +#' +#' @export +piercing.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + piercing.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLPIERCING_lookback <- piercing_lookback <- function( x, @@ -179,7 +202,7 @@ piercing.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ piercing.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLRICKSHAWMAN.R b/R/ta_CDLRICKSHAWMAN.R index 4d697ae40..6e1898764 100644 --- a/R/ta_CDLRICKSHAWMAN.R +++ b/R/ta_CDLRICKSHAWMAN.R @@ -77,35 +77,33 @@ rickshaw_man.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLRICKSHAWMAN, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLRICKSHAWMAN, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLRICKSHAWMAN" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ rickshaw_man.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( rickshaw_man.default( x = x, cols = cols, @@ -141,14 +139,39 @@ rickshaw_man.matrix <- function( na.bridge = FALSE, ... ) { - rickshaw_man.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + rickshaw_man.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases rickshaw_man +#' +#' @export +rickshaw_man.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + rickshaw_man.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLRICKSHAWMAN_lookback <- rickshawMan_lookback <- rickshaw_man_lookback <- function( x, @@ -186,7 +209,7 @@ rickshaw_man.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ rickshaw_man.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLRISEFALL3METHODS.R b/R/ta_CDLRISEFALL3METHODS.R index 17ce29d27..6528f17b3 100644 --- a/R/ta_CDLRISEFALL3METHODS.R +++ b/R/ta_CDLRISEFALL3METHODS.R @@ -77,35 +77,33 @@ rise_fall_3_methods.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLRISEFALL3METHODS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLRISEFALL3METHODS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLRISEFALL3METHODS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ rise_fall_3_methods.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( rise_fall_3_methods.default( x = x, cols = cols, @@ -141,14 +139,39 @@ rise_fall_3_methods.matrix <- function( na.bridge = FALSE, ... ) { - rise_fall_3_methods.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + rise_fall_3_methods.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases rise_fall_3_methods +#' +#' @export +rise_fall_3_methods.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + rise_fall_3_methods.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLRISEFALL3METHODS_lookback <- riseFall3Methods_lookback <- rise_fall_3_methods_lookback <- function( x, @@ -186,7 +209,7 @@ rise_fall_3_methods.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ rise_fall_3_methods.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSEPARATINGLINES.R b/R/ta_CDLSEPARATINGLINES.R index da857c8f0..8f5c6ab14 100644 --- a/R/ta_CDLSEPARATINGLINES.R +++ b/R/ta_CDLSEPARATINGLINES.R @@ -77,35 +77,33 @@ separating_lines.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSEPARATINGLINES, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSEPARATINGLINES, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSEPARATINGLINES" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ separating_lines.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( separating_lines.default( x = x, cols = cols, @@ -141,14 +139,39 @@ separating_lines.matrix <- function( na.bridge = FALSE, ... ) { - separating_lines.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + separating_lines.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases separating_lines +#' +#' @export +separating_lines.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + separating_lines.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSEPARATINGLINES_lookback <- separatingLines_lookback <- separating_lines_lookback <- function( x, @@ -186,7 +209,7 @@ separating_lines.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ separating_lines.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSHOOTINGSTAR.R b/R/ta_CDLSHOOTINGSTAR.R index 77b1f68c3..bac07392d 100644 --- a/R/ta_CDLSHOOTINGSTAR.R +++ b/R/ta_CDLSHOOTINGSTAR.R @@ -77,35 +77,33 @@ shooting_star.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSHOOTINGSTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSHOOTINGSTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSHOOTINGSTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ shooting_star.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( shooting_star.default( x = x, cols = cols, @@ -141,14 +139,39 @@ shooting_star.matrix <- function( na.bridge = FALSE, ... ) { - shooting_star.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + shooting_star.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases shooting_star +#' +#' @export +shooting_star.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + shooting_star.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSHOOTINGSTAR_lookback <- shootingStar_lookback <- shooting_star_lookback <- function( x, @@ -186,7 +209,7 @@ shooting_star.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ shooting_star.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSHORTLINE.R b/R/ta_CDLSHORTLINE.R index 4044bb321..d9dfab58a 100644 --- a/R/ta_CDLSHORTLINE.R +++ b/R/ta_CDLSHORTLINE.R @@ -77,35 +77,33 @@ short_line.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSHORTLINE, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSHORTLINE, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSHORTLINE" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ short_line.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( short_line.default( x = x, cols = cols, @@ -141,14 +139,39 @@ short_line.matrix <- function( na.bridge = FALSE, ... ) { - short_line.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + short_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases short_line +#' +#' @export +short_line.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + short_line.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSHORTLINE_lookback <- shortLine_lookback <- short_line_lookback <- function( x, @@ -186,7 +209,7 @@ short_line.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ short_line.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSPINNINGTOP.R b/R/ta_CDLSPINNINGTOP.R index e03f61f18..1443cec3d 100644 --- a/R/ta_CDLSPINNINGTOP.R +++ b/R/ta_CDLSPINNINGTOP.R @@ -77,35 +77,33 @@ spinning_top.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSPINNINGTOP, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSPINNINGTOP, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSPINNINGTOP" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ spinning_top.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( spinning_top.default( x = x, cols = cols, @@ -141,14 +139,39 @@ spinning_top.matrix <- function( na.bridge = FALSE, ... ) { - spinning_top.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + spinning_top.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases spinning_top +#' +#' @export +spinning_top.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + spinning_top.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSPINNINGTOP_lookback <- spinningTop_lookback <- spinning_top_lookback <- function( x, @@ -186,7 +209,7 @@ spinning_top.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ spinning_top.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSTALLEDPATTERN.R b/R/ta_CDLSTALLEDPATTERN.R index 7812764a2..4212dee12 100644 --- a/R/ta_CDLSTALLEDPATTERN.R +++ b/R/ta_CDLSTALLEDPATTERN.R @@ -77,35 +77,33 @@ stalled_pattern.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSTALLEDPATTERN, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSTALLEDPATTERN, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSTALLEDPATTERN" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ stalled_pattern.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( stalled_pattern.default( x = x, cols = cols, @@ -141,14 +139,39 @@ stalled_pattern.matrix <- function( na.bridge = FALSE, ... ) { - stalled_pattern.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + stalled_pattern.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases stalled_pattern +#' +#' @export +stalled_pattern.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + stalled_pattern.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSTALLEDPATTERN_lookback <- stalledPattern_lookback <- stalled_pattern_lookback <- function( x, @@ -186,7 +209,7 @@ stalled_pattern.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ stalled_pattern.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLSTICKSANDWICH.R b/R/ta_CDLSTICKSANDWICH.R index 5c554bea9..5adf2a511 100644 --- a/R/ta_CDLSTICKSANDWICH.R +++ b/R/ta_CDLSTICKSANDWICH.R @@ -77,35 +77,33 @@ stick_sandwich.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLSTICKSANDWICH, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLSTICKSANDWICH, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLSTICKSANDWICH" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ stick_sandwich.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( stick_sandwich.default( x = x, cols = cols, @@ -141,14 +139,39 @@ stick_sandwich.matrix <- function( na.bridge = FALSE, ... ) { - stick_sandwich.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + stick_sandwich.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases stick_sandwich +#' +#' @export +stick_sandwich.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + stick_sandwich.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLSTICKSANDWICH_lookback <- stickSandwich_lookback <- stick_sandwich_lookback <- function( x, @@ -186,7 +209,7 @@ stick_sandwich.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ stick_sandwich.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLTAKURI.R b/R/ta_CDLTAKURI.R index 6273baa29..66f468a1a 100644 --- a/R/ta_CDLTAKURI.R +++ b/R/ta_CDLTAKURI.R @@ -70,35 +70,33 @@ takuri.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLTAKURI, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLTAKURI, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLTAKURI" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ takuri.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( takuri.default( x = x, cols = cols, @@ -134,14 +132,39 @@ takuri.matrix <- function( na.bridge = FALSE, ... ) { - takuri.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + takuri.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases takuri +#' +#' @export +takuri.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + takuri.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLTAKURI_lookback <- takuri_lookback <- function( x, @@ -179,7 +202,7 @@ takuri.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ takuri.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLTASUKIGAP.R b/R/ta_CDLTASUKIGAP.R index eb77bc8a3..32bf8dd06 100644 --- a/R/ta_CDLTASUKIGAP.R +++ b/R/ta_CDLTASUKIGAP.R @@ -77,35 +77,33 @@ tasuki_gap.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLTASUKIGAP, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLTASUKIGAP, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLTASUKIGAP" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ tasuki_gap.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( tasuki_gap.default( x = x, cols = cols, @@ -141,14 +139,39 @@ tasuki_gap.matrix <- function( na.bridge = FALSE, ... ) { - tasuki_gap.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + tasuki_gap.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases tasuki_gap +#' +#' @export +tasuki_gap.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + tasuki_gap.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLTASUKIGAP_lookback <- tasukiGap_lookback <- tasuki_gap_lookback <- function( x, @@ -186,7 +209,7 @@ tasuki_gap.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ tasuki_gap.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLTHRUSTING.R b/R/ta_CDLTHRUSTING.R index e724fe13a..cc9a891c1 100644 --- a/R/ta_CDLTHRUSTING.R +++ b/R/ta_CDLTHRUSTING.R @@ -70,35 +70,33 @@ thrusting.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLTHRUSTING, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLTHRUSTING, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLTHRUSTING" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ thrusting.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( thrusting.default( x = x, cols = cols, @@ -134,14 +132,39 @@ thrusting.matrix <- function( na.bridge = FALSE, ... ) { - thrusting.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + thrusting.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases thrusting +#' +#' @export +thrusting.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + thrusting.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLTHRUSTING_lookback <- thrusting_lookback <- function( x, @@ -179,7 +202,7 @@ thrusting.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ thrusting.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLTRISTAR.R b/R/ta_CDLTRISTAR.R index 46d99997a..65584fabd 100644 --- a/R/ta_CDLTRISTAR.R +++ b/R/ta_CDLTRISTAR.R @@ -70,35 +70,33 @@ tristar.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLTRISTAR, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLTRISTAR, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLTRISTAR" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -114,7 +112,7 @@ tristar.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( tristar.default( x = x, cols = cols, @@ -134,14 +132,39 @@ tristar.matrix <- function( na.bridge = FALSE, ... ) { - tristar.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + tristar.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases tristar +#' +#' @export +tristar.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + tristar.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLTRISTAR_lookback <- tristar_lookback <- function( x, @@ -179,7 +202,7 @@ tristar.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -237,7 +260,7 @@ tristar.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLUNIQUE3RIVER.R b/R/ta_CDLUNIQUE3RIVER.R index 19c84bbe8..08699e581 100644 --- a/R/ta_CDLUNIQUE3RIVER.R +++ b/R/ta_CDLUNIQUE3RIVER.R @@ -77,35 +77,33 @@ unique_3_river.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLUNIQUE3RIVER, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLUNIQUE3RIVER, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLUNIQUE3RIVER" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ unique_3_river.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( unique_3_river.default( x = x, cols = cols, @@ -141,14 +139,39 @@ unique_3_river.matrix <- function( na.bridge = FALSE, ... ) { - unique_3_river.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + unique_3_river.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases unique_3_river +#' +#' @export +unique_3_river.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + unique_3_river.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLUNIQUE3RIVER_lookback <- unique3River_lookback <- unique_3_river_lookback <- function( x, @@ -186,7 +209,7 @@ unique_3_river.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ unique_3_river.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLUPSIDEGAP2CROWS.R b/R/ta_CDLUPSIDEGAP2CROWS.R index 0f4530ec1..182cca25d 100644 --- a/R/ta_CDLUPSIDEGAP2CROWS.R +++ b/R/ta_CDLUPSIDEGAP2CROWS.R @@ -77,35 +77,33 @@ upside_gap_2_crows.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLUPSIDEGAP2CROWS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLUPSIDEGAP2CROWS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLUPSIDEGAP2CROWS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ upside_gap_2_crows.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( upside_gap_2_crows.default( x = x, cols = cols, @@ -141,14 +139,39 @@ upside_gap_2_crows.matrix <- function( na.bridge = FALSE, ... ) { - upside_gap_2_crows.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + upside_gap_2_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases upside_gap_2_crows +#' +#' @export +upside_gap_2_crows.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + upside_gap_2_crows.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLUPSIDEGAP2CROWS_lookback <- upsideGap2Crows_lookback <- upside_gap_2_crows_lookback <- function( x, @@ -186,7 +209,7 @@ upside_gap_2_crows.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ upside_gap_2_crows.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CDLXSIDEGAP3METHODS.R b/R/ta_CDLXSIDEGAP3METHODS.R index 50b926a4a..d04485fa3 100644 --- a/R/ta_CDLXSIDEGAP3METHODS.R +++ b/R/ta_CDLXSIDEGAP3METHODS.R @@ -77,35 +77,33 @@ xside_gap_3_methods.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + high + low + close, - data = x, + x = x, + formula.default = ~ open + high + low + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( - C_impl_ta_CDLXSIDEGAP3METHODS, - constructed_series[[1]], - constructed_series[[2]], - constructed_series[[3]], - constructed_series[[4]], - normalize, - as.logical(na.bridge) - ) + x <- .Call( + C_impl_ta_CDLXSIDEGAP3METHODS, + constructed_series[[1]], + constructed_series[[2]], + constructed_series[[3]], + constructed_series[[4]], + normalize, + as.logical(na.bridge) ) ## add column name colnames(x) <- "CDLXSIDEGAP3METHODS" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +119,7 @@ xside_gap_3_methods.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( xside_gap_3_methods.default( x = x, cols = cols, @@ -141,14 +139,39 @@ xside_gap_3_methods.matrix <- function( na.bridge = FALSE, ... ) { - xside_gap_3_methods.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + xside_gap_3_methods.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } +#' @usage NULL +#' @aliases xside_gap_3_methods +#' +#' @export +xside_gap_3_methods.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + xside_gap_3_methods.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + + #' @usage NULL CDLXSIDEGAP3METHODS_lookback <- xsideGap3Methods_lookback <- xside_gap_3_methods_lookback <- function( x, @@ -186,7 +209,7 @@ xside_gap_3_methods.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) @@ -244,7 +267,7 @@ xside_gap_3_methods.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + high + low + close, + formula.default = ~ open + high + low + close, ... ) diff --git a/R/ta_CMF.R b/R/ta_CMF.R index fe14c12fc..ed58ce830 100644 --- a/R/ta_CMF.R +++ b/R/ta_CMF.R @@ -58,15 +58,15 @@ chaikin_money_flow.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -81,7 +81,7 @@ chaikin_money_flow.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -98,7 +98,7 @@ chaikin_money_flow.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( chaikin_money_flow.default( x = x, cols = cols, @@ -120,12 +120,38 @@ chaikin_money_flow.matrix <- function( na.bridge = FALSE, ... ) { - chaikin_money_flow.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + chaikin_money_flow.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases chaikin_money_flow +#' +#' @export +chaikin_money_flow.xts <- function( + x, + cols, + timePeriod = 20, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + chaikin_money_flow.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -172,7 +198,7 @@ chaikin_money_flow.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) @@ -272,7 +298,7 @@ chaikin_money_flow.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) diff --git a/R/ta_CMO.R b/R/ta_CMO.R index 87a726285..b1cabeb13 100644 --- a/R/ta_CMO.R +++ b/R/ta_CMO.R @@ -58,15 +58,15 @@ chande_momentum_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ chande_momentum_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ chande_momentum_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( chande_momentum_oscillator.default( x = x, cols = cols, @@ -117,12 +117,38 @@ chande_momentum_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - chande_momentum_oscillator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + chande_momentum_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases chande_momentum_oscillator +#' +#' @export +chande_momentum_oscillator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + chande_momentum_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ chande_momentum_oscillator.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ chande_momentum_oscillator.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -206,7 +237,7 @@ chande_momentum_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -313,7 +344,7 @@ chande_momentum_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_CMOU.R b/R/ta_CMOU.R index c9a45bbd3..1acb9f126 100644 --- a/R/ta_CMOU.R +++ b/R/ta_CMOU.R @@ -58,15 +58,15 @@ unsmoothed_chande_momentum_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ unsmoothed_chande_momentum_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ unsmoothed_chande_momentum_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( unsmoothed_chande_momentum_oscillator.default( x = x, cols = cols, @@ -117,12 +117,38 @@ unsmoothed_chande_momentum_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - unsmoothed_chande_momentum_oscillator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + unsmoothed_chande_momentum_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases unsmoothed_chande_momentum_oscillator +#' +#' @export +unsmoothed_chande_momentum_oscillator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + unsmoothed_chande_momentum_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ unsmoothed_chande_momentum_oscillator.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ unsmoothed_chande_momentum_oscillator.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -204,7 +235,7 @@ unsmoothed_chande_momentum_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -304,7 +335,7 @@ unsmoothed_chande_momentum_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_CORREL.R b/R/ta_CORREL.R index 2f2aa1a1e..ffda17a8d 100644 --- a/R/ta_CORREL.R +++ b/R/ta_CORREL.R @@ -47,6 +47,23 @@ rolling_correlation.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + assert( + x = NCOL(y) == 1L, + call = sys.call(sys.parent()), + "Expected 'y' to be univariate.", + paste0("Got ", NCOL(y), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -63,6 +80,7 @@ rolling_correlation.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -97,6 +115,57 @@ rolling_correlation.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_correlation +#' +#' @export +rolling_correlation.xts <- function( + x, + y, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + assert( + x = NCOL(y) == 1L, + call = sys.call(sys.parent()), + "Expected 'y' to be univariate.", + paste0("Got ", NCOL(y), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_CORREL, + as.double(x), + as.double(y), + as.integer(timePeriod), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL CORREL_lookback <- rollingCorrelation_lookback <- rolling_correlation_lookback <- function( x, diff --git a/R/ta_DEMA.R b/R/ta_DEMA.R index 80ae501f6..30b99cc7e 100644 --- a/R/ta_DEMA.R +++ b/R/ta_DEMA.R @@ -84,15 +84,15 @@ double_exponential_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ double_exponential_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ double_exponential_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( double_exponential_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ double_exponential_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - double_exponential_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + double_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases double_exponential_moving_average +#' +#' @export +double_exponential_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + double_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases double_exponential_moving_average #' @@ -171,6 +198,10 @@ double_exponential_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ double_exponential_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ double_exponential_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ double_exponential_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_DX.R b/R/ta_DX.R index 4670c97f5..3d4ba1a3a 100644 --- a/R/ta_DX.R +++ b/R/ta_DX.R @@ -58,15 +58,15 @@ directional_movement_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ directional_movement_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ directional_movement_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( directional_movement_index.default( x = x, cols = cols, @@ -119,12 +119,38 @@ directional_movement_index.matrix <- function( na.bridge = FALSE, ... ) { - directional_movement_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + directional_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases directional_movement_index +#' +#' @export +directional_movement_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + directional_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -171,7 +197,7 @@ directional_movement_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -273,7 +299,7 @@ directional_movement_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_EMA.R b/R/ta_EMA.R index 6ace188d0..a54df086d 100644 --- a/R/ta_EMA.R +++ b/R/ta_EMA.R @@ -84,15 +84,15 @@ exponential_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ exponential_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ exponential_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( exponential_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ exponential_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - exponential_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases exponential_moving_average +#' +#' @export +exponential_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases exponential_moving_average #' @@ -171,6 +198,10 @@ exponential_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ exponential_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ exponential_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ exponential_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HMA.R b/R/ta_HMA.R index 53692c7c6..0cec151d8 100644 --- a/R/ta_HMA.R +++ b/R/ta_HMA.R @@ -84,15 +84,15 @@ hull_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ hull_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ hull_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( hull_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ hull_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - hull_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + hull_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases hull_moving_average +#' +#' @export +hull_moving_average.xts <- function( + x, + cols, + timePeriod = 20, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + hull_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases hull_moving_average #' @@ -171,6 +198,10 @@ hull_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ hull_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ hull_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ hull_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_DCPERIOD.R b/R/ta_HT_DCPERIOD.R index 6d408ee10..346b8f8fd 100644 --- a/R/ta_HT_DCPERIOD.R +++ b/R/ta_HT_DCPERIOD.R @@ -56,15 +56,15 @@ dominant_cycle_period.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -75,7 +75,7 @@ dominant_cycle_period.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -91,7 +91,7 @@ dominant_cycle_period.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( dominant_cycle_period.default( x = x, cols = cols, @@ -111,11 +111,35 @@ dominant_cycle_period.matrix <- function( na.bridge = FALSE, ... ) { - dominant_cycle_period.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + dominant_cycle_period.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases dominant_cycle_period +#' +#' @export +dominant_cycle_period.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + dominant_cycle_period.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -149,6 +173,10 @@ dominant_cycle_period.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -160,6 +188,7 @@ dominant_cycle_period.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -192,7 +221,7 @@ dominant_cycle_period.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -292,7 +321,7 @@ dominant_cycle_period.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_DCPHASE.R b/R/ta_HT_DCPHASE.R index b4bb51e34..177d2a31d 100644 --- a/R/ta_HT_DCPHASE.R +++ b/R/ta_HT_DCPHASE.R @@ -56,15 +56,15 @@ dominant_cycle_phase.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -75,7 +75,7 @@ dominant_cycle_phase.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -91,7 +91,7 @@ dominant_cycle_phase.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( dominant_cycle_phase.default( x = x, cols = cols, @@ -111,11 +111,35 @@ dominant_cycle_phase.matrix <- function( na.bridge = FALSE, ... ) { - dominant_cycle_phase.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + dominant_cycle_phase.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases dominant_cycle_phase +#' +#' @export +dominant_cycle_phase.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + dominant_cycle_phase.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -149,6 +173,10 @@ dominant_cycle_phase.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -160,6 +188,7 @@ dominant_cycle_phase.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -192,7 +221,7 @@ dominant_cycle_phase.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -292,7 +321,7 @@ dominant_cycle_phase.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_PHASOR.R b/R/ta_HT_PHASOR.R index 3351345ca..91bd1f712 100644 --- a/R/ta_HT_PHASOR.R +++ b/R/ta_HT_PHASOR.R @@ -56,15 +56,15 @@ phasor_components.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -75,7 +75,7 @@ phasor_components.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -91,7 +91,7 @@ phasor_components.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( phasor_components.default( x = x, cols = cols, @@ -111,11 +111,35 @@ phasor_components.matrix <- function( na.bridge = FALSE, ... ) { - phasor_components.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + phasor_components.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases phasor_components +#' +#' @export +phasor_components.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + phasor_components.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -149,6 +173,10 @@ phasor_components.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -160,6 +188,7 @@ phasor_components.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -192,7 +221,7 @@ phasor_components.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -300,7 +329,7 @@ phasor_components.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_SINE.R b/R/ta_HT_SINE.R index 75c12931a..f79ee6e7b 100644 --- a/R/ta_HT_SINE.R +++ b/R/ta_HT_SINE.R @@ -56,15 +56,15 @@ sine_wave.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -75,7 +75,7 @@ sine_wave.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -91,7 +91,7 @@ sine_wave.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( sine_wave.default( x = x, cols = cols, @@ -111,11 +111,35 @@ sine_wave.matrix <- function( na.bridge = FALSE, ... ) { - sine_wave.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + sine_wave.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases sine_wave +#' +#' @export +sine_wave.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + sine_wave.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -149,6 +173,10 @@ sine_wave.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -160,6 +188,7 @@ sine_wave.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -192,7 +221,7 @@ sine_wave.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -298,7 +327,7 @@ sine_wave.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_TRENDLINE.R b/R/ta_HT_TRENDLINE.R index 4d3c6e1fa..dff115933 100644 --- a/R/ta_HT_TRENDLINE.R +++ b/R/ta_HT_TRENDLINE.R @@ -49,15 +49,15 @@ trendline.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -68,7 +68,7 @@ trendline.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -84,7 +84,7 @@ trendline.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( trendline.default( x = x, cols = cols, @@ -104,11 +104,35 @@ trendline.matrix <- function( na.bridge = FALSE, ... ) { - trendline.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + trendline.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases trendline +#' +#' @export +trendline.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + trendline.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -142,6 +166,10 @@ trendline.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -153,6 +181,7 @@ trendline.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -184,7 +213,7 @@ trendline.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -253,7 +282,7 @@ trendline.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_HT_TRENDMODE.R b/R/ta_HT_TRENDMODE.R index e9545a78c..d5e7f9cbc 100644 --- a/R/ta_HT_TRENDMODE.R +++ b/R/ta_HT_TRENDMODE.R @@ -56,15 +56,15 @@ trend_cycle_mode.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -75,7 +75,7 @@ trend_cycle_mode.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -91,7 +91,7 @@ trend_cycle_mode.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( trend_cycle_mode.default( x = x, cols = cols, @@ -111,11 +111,35 @@ trend_cycle_mode.matrix <- function( na.bridge = FALSE, ... ) { - trend_cycle_mode.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + trend_cycle_mode.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases trend_cycle_mode +#' +#' @export +trend_cycle_mode.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + trend_cycle_mode.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -149,6 +173,10 @@ trend_cycle_mode.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -160,6 +188,7 @@ trend_cycle_mode.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -192,7 +221,7 @@ trend_cycle_mode.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -291,7 +320,7 @@ trend_cycle_mode.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_IMI.R b/R/ta_IMI.R index 255b3158a..0622c0a71 100644 --- a/R/ta_IMI.R +++ b/R/ta_IMI.R @@ -58,15 +58,15 @@ intraday_movement_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ open + close, - data = x, + x = x, + formula = cols, + formula.default = ~ open + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -79,7 +79,7 @@ intraday_movement_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -96,7 +96,7 @@ intraday_movement_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( intraday_movement_index.default( x = x, cols = cols, @@ -118,12 +118,38 @@ intraday_movement_index.matrix <- function( na.bridge = FALSE, ... ) { - intraday_movement_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + intraday_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases intraday_movement_index +#' +#' @export +intraday_movement_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + intraday_movement_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -170,7 +196,7 @@ intraday_movement_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + close, + formula.default = ~ open + close, ... ) @@ -268,7 +294,7 @@ intraday_movement_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ open + close, + formula.default = ~ open + close, ... ) diff --git a/R/ta_KAMA.R b/R/ta_KAMA.R index 8b11760b4..99fa17322 100644 --- a/R/ta_KAMA.R +++ b/R/ta_KAMA.R @@ -84,15 +84,15 @@ kaufman_adaptive_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ kaufman_adaptive_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ kaufman_adaptive_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( kaufman_adaptive_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ kaufman_adaptive_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - kaufman_adaptive_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + kaufman_adaptive_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases kaufman_adaptive_moving_average +#' +#' @export +kaufman_adaptive_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + kaufman_adaptive_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases kaufman_adaptive_moving_average #' @@ -171,6 +198,10 @@ kaufman_adaptive_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ kaufman_adaptive_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ kaufman_adaptive_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ kaufman_adaptive_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MACD.R b/R/ta_MACD.R index de98ff7d3..07b44fdd1 100644 --- a/R/ta_MACD.R +++ b/R/ta_MACD.R @@ -64,15 +64,15 @@ moving_average_convergence_divergence.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -86,7 +86,7 @@ moving_average_convergence_divergence.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -105,7 +105,7 @@ moving_average_convergence_divergence.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( moving_average_convergence_divergence.default( x = x, cols = cols, @@ -131,14 +131,44 @@ moving_average_convergence_divergence.matrix <- function( na.bridge = FALSE, ... ) { - moving_average_convergence_divergence.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - slowPeriod = slowPeriod, - signalPeriod = signalPeriod, - na.bridge = na.bridge, - ... + as.matrix( + moving_average_convergence_divergence.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + signalPeriod = signalPeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases moving_average_convergence_divergence +#' +#' @export +moving_average_convergence_divergence.xts <- function( + x, + cols, + fastPeriod = 12, + slowPeriod = 26, + signalPeriod = 9, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + moving_average_convergence_divergence.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + signalPeriod = signalPeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -181,6 +211,10 @@ moving_average_convergence_divergence.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -195,6 +229,7 @@ moving_average_convergence_divergence.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -230,7 +265,7 @@ moving_average_convergence_divergence.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -365,7 +400,7 @@ moving_average_convergence_divergence.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MACDEXT.R b/R/ta_MACDEXT.R index 0ff8884b5..2964a874a 100644 --- a/R/ta_MACDEXT.R +++ b/R/ta_MACDEXT.R @@ -73,15 +73,15 @@ extended_moving_average_convergence_divergence.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -98,7 +98,7 @@ extended_moving_average_convergence_divergence.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -120,7 +120,7 @@ extended_moving_average_convergence_divergence.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( extended_moving_average_convergence_divergence.default( x = x, cols = cols, @@ -152,17 +152,53 @@ extended_moving_average_convergence_divergence.matrix <- function( na.bridge = FALSE, ... ) { - extended_moving_average_convergence_divergence.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - fastMa = fastMa, - slowPeriod = slowPeriod, - slowMa = slowMa, - signalPeriod = signalPeriod, - signalMa = signalMa, - na.bridge = na.bridge, - ... + as.matrix( + extended_moving_average_convergence_divergence.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + fastMa = fastMa, + slowPeriod = slowPeriod, + slowMa = slowMa, + signalPeriod = signalPeriod, + signalMa = signalMa, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases extended_moving_average_convergence_divergence +#' +#' @export +extended_moving_average_convergence_divergence.xts <- function( + x, + cols, + fastPeriod = 12, + fastMa = 0, + slowPeriod = 26, + slowMa = 0, + signalPeriod = 9, + signalMa = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + extended_moving_average_convergence_divergence.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + fastMa = fastMa, + slowPeriod = slowPeriod, + slowMa = slowMa, + signalPeriod = signalPeriod, + signalMa = signalMa, + na.bridge = na.bridge, + ... + ) ) } @@ -214,6 +250,10 @@ extended_moving_average_convergence_divergence.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -231,6 +271,7 @@ extended_moving_average_convergence_divergence.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -269,7 +310,7 @@ extended_moving_average_convergence_divergence.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -410,7 +451,7 @@ extended_moving_average_convergence_divergence.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MACDFIX.R b/R/ta_MACDFIX.R index 17eb1cc3f..283a23a5a 100644 --- a/R/ta_MACDFIX.R +++ b/R/ta_MACDFIX.R @@ -58,15 +58,15 @@ fixed_moving_average_convergence_divergence.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ fixed_moving_average_convergence_divergence.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ fixed_moving_average_convergence_divergence.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( fixed_moving_average_convergence_divergence.default( x = x, cols = cols, @@ -117,12 +117,38 @@ fixed_moving_average_convergence_divergence.matrix <- function( na.bridge = FALSE, ... ) { - fixed_moving_average_convergence_divergence.default( - x = x, - cols = cols, - signalPeriod = signalPeriod, - na.bridge = na.bridge, - ... + as.matrix( + fixed_moving_average_convergence_divergence.default( + x = x, + cols = cols, + signalPeriod = signalPeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases fixed_moving_average_convergence_divergence +#' +#' @export +fixed_moving_average_convergence_divergence.xts <- function( + x, + cols, + signalPeriod = 9, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + fixed_moving_average_convergence_divergence.default( + x = x, + cols = cols, + signalPeriod = signalPeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ fixed_moving_average_convergence_divergence.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ fixed_moving_average_convergence_divergence.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -204,7 +235,7 @@ fixed_moving_average_convergence_divergence.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -333,7 +364,7 @@ fixed_moving_average_convergence_divergence.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MAMA.R b/R/ta_MAMA.R index a7105b918..bca143804 100644 --- a/R/ta_MAMA.R +++ b/R/ta_MAMA.R @@ -99,15 +99,15 @@ mesa_adaptive_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -120,7 +120,7 @@ mesa_adaptive_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -139,7 +139,7 @@ mesa_adaptive_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( mesa_adaptive_moving_average.default( x = x, cols = cols, @@ -165,17 +165,48 @@ mesa_adaptive_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - mesa_adaptive_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - fastLimit = fastLimit, - slowLimit = slowLimit, - na.bridge = na.bridge, - ... + as.matrix( + mesa_adaptive_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + fastLimit = fastLimit, + slowLimit = slowLimit, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases mesa_adaptive_moving_average +#' +#' @export +mesa_adaptive_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + fastLimit = 0.5, + slowLimit = 0.05, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + mesa_adaptive_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + fastLimit = fastLimit, + slowLimit = slowLimit, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases mesa_adaptive_moving_average #' @@ -197,6 +228,10 @@ mesa_adaptive_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -210,6 +245,7 @@ mesa_adaptive_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -260,7 +296,7 @@ mesa_adaptive_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -333,7 +369,7 @@ mesa_adaptive_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MAVP.R b/R/ta_MAVP.R index cc6135e12..884e70da8 100644 --- a/R/ta_MAVP.R +++ b/R/ta_MAVP.R @@ -69,15 +69,15 @@ variable_moving_average_period.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -92,7 +92,7 @@ variable_moving_average_period.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -112,7 +112,7 @@ variable_moving_average_period.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( variable_moving_average_period.default( x = x, cols = cols, @@ -140,15 +140,47 @@ variable_moving_average_period.matrix <- function( na.bridge = FALSE, ... ) { - variable_moving_average_period.default( - x = x, - cols = cols, - periods = periods, - minimumPeriod = minimumPeriod, - maximumPeriod = maximumPeriod, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + variable_moving_average_period.default( + x = x, + cols = cols, + periods = periods, + minimumPeriod = minimumPeriod, + maximumPeriod = maximumPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases variable_moving_average_period +#' +#' @export +variable_moving_average_period.xts <- function( + x, + cols, + periods, + minimumPeriod = 2, + maximumPeriod = 30, + maType = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + variable_moving_average_period.default( + x = x, + cols = cols, + periods = periods, + minimumPeriod = minimumPeriod, + maximumPeriod = maximumPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -193,6 +225,10 @@ variable_moving_average_period.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -208,6 +244,7 @@ variable_moving_average_period.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -243,7 +280,7 @@ variable_moving_average_period.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -333,7 +370,7 @@ variable_moving_average_period.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MAX.R b/R/ta_MAX.R index c76d35519..c9986b3e2 100644 --- a/R/ta_MAX.R +++ b/R/ta_MAX.R @@ -45,6 +45,16 @@ rolling_maximum.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -60,6 +70,7 @@ rolling_maximum.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -92,6 +103,48 @@ rolling_maximum.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_maximum +#' +#' @export +rolling_maximum.xts <- function( + x, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_MAX, + as.double(x), + as.integer(timePeriod), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL MAX_lookback <- rollingMaximum_lookback <- rolling_maximum_lookback <- function( x, diff --git a/R/ta_MEDPRICE.R b/R/ta_MEDPRICE.R index a81bd341b..298af37eb 100644 --- a/R/ta_MEDPRICE.R +++ b/R/ta_MEDPRICE.R @@ -56,15 +56,15 @@ median_price.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -76,7 +76,7 @@ median_price.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -92,7 +92,7 @@ median_price.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( median_price.default( x = x, cols = cols, @@ -112,11 +112,35 @@ median_price.matrix <- function( na.bridge = FALSE, ... ) { - median_price.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + median_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases median_price +#' +#' @export +median_price.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + median_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } diff --git a/R/ta_MFI.R b/R/ta_MFI.R index d3262386d..de5bf14f8 100644 --- a/R/ta_MFI.R +++ b/R/ta_MFI.R @@ -58,15 +58,15 @@ money_flow_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -81,7 +81,7 @@ money_flow_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -98,7 +98,7 @@ money_flow_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( money_flow_index.default( x = x, cols = cols, @@ -120,12 +120,38 @@ money_flow_index.matrix <- function( na.bridge = FALSE, ... ) { - money_flow_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + money_flow_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases money_flow_index +#' +#' @export +money_flow_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + money_flow_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -174,7 +200,7 @@ money_flow_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) @@ -272,7 +298,7 @@ money_flow_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close + volume, + formula.default = ~ high + low + close + volume, ... ) diff --git a/R/ta_MIDPOINT.R b/R/ta_MIDPOINT.R index 12e43cce5..f096fa783 100644 --- a/R/ta_MIDPOINT.R +++ b/R/ta_MIDPOINT.R @@ -58,15 +58,15 @@ midpoint_period.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ midpoint_period.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ midpoint_period.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( midpoint_period.default( x = x, cols = cols, @@ -117,12 +117,38 @@ midpoint_period.matrix <- function( na.bridge = FALSE, ... ) { - midpoint_period.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + midpoint_period.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases midpoint_period +#' +#' @export +midpoint_period.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + midpoint_period.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ midpoint_period.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ midpoint_period.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -203,7 +234,7 @@ midpoint_period.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -282,7 +313,7 @@ midpoint_period.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_MIDPRICE.R b/R/ta_MIDPRICE.R index 9905c4812..73d5d36fc 100644 --- a/R/ta_MIDPRICE.R +++ b/R/ta_MIDPRICE.R @@ -58,15 +58,15 @@ midpoint_price.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -79,7 +79,7 @@ midpoint_price.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -96,7 +96,7 @@ midpoint_price.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( midpoint_price.default( x = x, cols = cols, @@ -118,12 +118,38 @@ midpoint_price.matrix <- function( na.bridge = FALSE, ... ) { - midpoint_price.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + midpoint_price.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases midpoint_price +#' +#' @export +midpoint_price.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + midpoint_price.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -169,7 +195,7 @@ midpoint_price.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -248,7 +274,7 @@ midpoint_price.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_MIN.R b/R/ta_MIN.R index 52d0d4db2..f66cbfc13 100644 --- a/R/ta_MIN.R +++ b/R/ta_MIN.R @@ -45,6 +45,16 @@ rolling_minimum.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -60,6 +70,7 @@ rolling_minimum.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -92,6 +103,48 @@ rolling_minimum.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_minimum +#' +#' @export +rolling_minimum.xts <- function( + x, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_MIN, + as.double(x), + as.integer(timePeriod), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL MIN_lookback <- rollingMinimum_lookback <- rolling_minimum_lookback <- function( x, diff --git a/R/ta_MINUS_DI.R b/R/ta_MINUS_DI.R index 2499c2134..d8556565a 100644 --- a/R/ta_MINUS_DI.R +++ b/R/ta_MINUS_DI.R @@ -58,15 +58,15 @@ minus_directional_indicator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ minus_directional_indicator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ minus_directional_indicator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( minus_directional_indicator.default( x = x, cols = cols, @@ -119,12 +119,38 @@ minus_directional_indicator.matrix <- function( na.bridge = FALSE, ... ) { - minus_directional_indicator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + minus_directional_indicator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases minus_directional_indicator +#' +#' @export +minus_directional_indicator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + minus_directional_indicator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -171,7 +197,7 @@ minus_directional_indicator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -264,7 +290,7 @@ minus_directional_indicator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_MINUS_DM.R b/R/ta_MINUS_DM.R index b31275164..7f076e457 100644 --- a/R/ta_MINUS_DM.R +++ b/R/ta_MINUS_DM.R @@ -58,15 +58,15 @@ minus_directional_movement.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -79,7 +79,7 @@ minus_directional_movement.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -96,7 +96,7 @@ minus_directional_movement.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( minus_directional_movement.default( x = x, cols = cols, @@ -118,12 +118,38 @@ minus_directional_movement.matrix <- function( na.bridge = FALSE, ... ) { - minus_directional_movement.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + minus_directional_movement.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases minus_directional_movement +#' +#' @export +minus_directional_movement.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + minus_directional_movement.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -170,7 +196,7 @@ minus_directional_movement.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -263,7 +289,7 @@ minus_directional_movement.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_MOM.R b/R/ta_MOM.R index 0b55a4ec5..8ba525ea2 100644 --- a/R/ta_MOM.R +++ b/R/ta_MOM.R @@ -51,15 +51,15 @@ momentum.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -71,7 +71,7 @@ momentum.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -88,7 +88,7 @@ momentum.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( momentum.default( x = x, cols = cols, @@ -110,12 +110,38 @@ momentum.matrix <- function( na.bridge = FALSE, ... ) { - momentum.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + momentum.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases momentum +#' +#' @export +momentum.xts <- function( + x, + cols, + timePeriod = 10, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + momentum.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -152,6 +178,10 @@ momentum.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -164,6 +194,7 @@ momentum.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -197,7 +228,7 @@ momentum.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -293,7 +324,7 @@ momentum.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_NATR.R b/R/ta_NATR.R index 715281eb9..ca2332d46 100644 --- a/R/ta_NATR.R +++ b/R/ta_NATR.R @@ -58,15 +58,15 @@ normalized_average_true_range.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ normalized_average_true_range.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ normalized_average_true_range.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( normalized_average_true_range.default( x = x, cols = cols, @@ -119,12 +119,38 @@ normalized_average_true_range.matrix <- function( na.bridge = FALSE, ... ) { - normalized_average_true_range.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + normalized_average_true_range.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases normalized_average_true_range +#' +#' @export +normalized_average_true_range.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + normalized_average_true_range.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -171,7 +197,7 @@ normalized_average_true_range.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -263,7 +289,7 @@ normalized_average_true_range.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_NVI.R b/R/ta_NVI.R index a03bb6b08..3cd74a09c 100644 --- a/R/ta_NVI.R +++ b/R/ta_NVI.R @@ -56,15 +56,15 @@ negative_volume_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -76,7 +76,7 @@ negative_volume_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -92,7 +92,7 @@ negative_volume_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( negative_volume_index.default( x = x, cols = cols, @@ -112,11 +112,35 @@ negative_volume_index.matrix <- function( na.bridge = FALSE, ... ) { - negative_volume_index.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + negative_volume_index.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases negative_volume_index +#' +#' @export +negative_volume_index.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + negative_volume_index.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -160,7 +184,7 @@ negative_volume_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) @@ -258,7 +282,7 @@ negative_volume_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) diff --git a/R/ta_OBV.R b/R/ta_OBV.R index a821dc4f2..bb83fc91c 100644 --- a/R/ta_OBV.R +++ b/R/ta_OBV.R @@ -56,15 +56,15 @@ on_balance_volume.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -76,7 +76,7 @@ on_balance_volume.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -92,7 +92,7 @@ on_balance_volume.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( on_balance_volume.default( x = x, cols = cols, @@ -112,11 +112,35 @@ on_balance_volume.matrix <- function( na.bridge = FALSE, ... ) { - on_balance_volume.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + on_balance_volume.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases on_balance_volume +#' +#' @export +on_balance_volume.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + on_balance_volume.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -160,7 +184,7 @@ on_balance_volume.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) @@ -248,7 +272,7 @@ on_balance_volume.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) diff --git a/R/ta_PLUS_DI.R b/R/ta_PLUS_DI.R index f5ac7c5c4..8a61e0eba 100644 --- a/R/ta_PLUS_DI.R +++ b/R/ta_PLUS_DI.R @@ -58,15 +58,15 @@ plus_directional_indicator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ plus_directional_indicator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ plus_directional_indicator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( plus_directional_indicator.default( x = x, cols = cols, @@ -119,12 +119,38 @@ plus_directional_indicator.matrix <- function( na.bridge = FALSE, ... ) { - plus_directional_indicator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + plus_directional_indicator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases plus_directional_indicator +#' +#' @export +plus_directional_indicator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + plus_directional_indicator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -171,7 +197,7 @@ plus_directional_indicator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -264,7 +290,7 @@ plus_directional_indicator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_PLUS_DM.R b/R/ta_PLUS_DM.R index c3bddf9a9..1948d1424 100644 --- a/R/ta_PLUS_DM.R +++ b/R/ta_PLUS_DM.R @@ -58,15 +58,15 @@ plus_directional_movement.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -79,7 +79,7 @@ plus_directional_movement.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -96,7 +96,7 @@ plus_directional_movement.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( plus_directional_movement.default( x = x, cols = cols, @@ -118,12 +118,38 @@ plus_directional_movement.matrix <- function( na.bridge = FALSE, ... ) { - plus_directional_movement.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + plus_directional_movement.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases plus_directional_movement +#' +#' @export +plus_directional_movement.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + plus_directional_movement.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -170,7 +196,7 @@ plus_directional_movement.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -263,7 +289,7 @@ plus_directional_movement.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_PPO.R b/R/ta_PPO.R index 3d1114877..a3447630b 100644 --- a/R/ta_PPO.R +++ b/R/ta_PPO.R @@ -64,15 +64,15 @@ percentage_price_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -86,7 +86,7 @@ percentage_price_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -105,7 +105,7 @@ percentage_price_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( percentage_price_oscillator.default( x = x, cols = cols, @@ -131,14 +131,44 @@ percentage_price_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - percentage_price_oscillator.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - slowPeriod = slowPeriod, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + percentage_price_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases percentage_price_oscillator +#' +#' @export +percentage_price_oscillator.xts <- function( + x, + cols, + fastPeriod = 12, + slowPeriod = 26, + maType = 1, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + percentage_price_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -181,6 +211,10 @@ percentage_price_oscillator.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -195,6 +229,7 @@ percentage_price_oscillator.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -230,7 +265,7 @@ percentage_price_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -331,7 +366,7 @@ percentage_price_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_PVI.R b/R/ta_PVI.R index 028442976..fb48b083d 100644 --- a/R/ta_PVI.R +++ b/R/ta_PVI.R @@ -56,15 +56,15 @@ positive_volume_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ close + volume, - data = x, + x = x, + formula = cols, + formula.default = ~ close + volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -76,7 +76,7 @@ positive_volume_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -92,7 +92,7 @@ positive_volume_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( positive_volume_index.default( x = x, cols = cols, @@ -112,11 +112,35 @@ positive_volume_index.matrix <- function( na.bridge = FALSE, ... ) { - positive_volume_index.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + positive_volume_index.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases positive_volume_index +#' +#' @export +positive_volume_index.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + positive_volume_index.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -160,7 +184,7 @@ positive_volume_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) @@ -258,7 +282,7 @@ positive_volume_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) diff --git a/R/ta_PVO.R b/R/ta_PVO.R index 4ac93d36c..b048354e8 100644 --- a/R/ta_PVO.R +++ b/R/ta_PVO.R @@ -64,15 +64,15 @@ percentage_volume_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~volume, - data = x, + x = x, + formula = cols, + formula.default = ~volume, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -86,7 +86,7 @@ percentage_volume_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -105,7 +105,7 @@ percentage_volume_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( percentage_volume_oscillator.default( x = x, cols = cols, @@ -131,14 +131,44 @@ percentage_volume_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - percentage_volume_oscillator.default( - x = x, - cols = cols, - fastPeriod = fastPeriod, - slowPeriod = slowPeriod, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + percentage_volume_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases percentage_volume_oscillator +#' +#' @export +percentage_volume_oscillator.xts <- function( + x, + cols, + fastPeriod = 12, + slowPeriod = 26, + maType = 1, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + percentage_volume_oscillator.default( + x = x, + cols = cols, + fastPeriod = fastPeriod, + slowPeriod = slowPeriod, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -181,6 +211,10 @@ percentage_volume_oscillator.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -195,6 +229,7 @@ percentage_volume_oscillator.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -230,7 +265,7 @@ percentage_volume_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~volume, + formula.default = ~volume, ... ) @@ -334,7 +369,7 @@ percentage_volume_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~volume, + formula.default = ~volume, ... ) diff --git a/R/ta_ROCR.R b/R/ta_ROCR.R index 3fc951278..af813def6 100644 --- a/R/ta_ROCR.R +++ b/R/ta_ROCR.R @@ -58,15 +58,15 @@ ratio_of_change.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ ratio_of_change.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ ratio_of_change.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ratio_of_change.default( x = x, cols = cols, @@ -117,12 +117,38 @@ ratio_of_change.matrix <- function( na.bridge = FALSE, ... ) { - ratio_of_change.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + ratio_of_change.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases ratio_of_change +#' +#' @export +ratio_of_change.xts <- function( + x, + cols, + timePeriod = 10, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + ratio_of_change.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ ratio_of_change.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ ratio_of_change.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -204,7 +235,7 @@ ratio_of_change.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -304,7 +335,7 @@ ratio_of_change.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_RSI.R b/R/ta_RSI.R index 92a06e855..f2634ae38 100644 --- a/R/ta_RSI.R +++ b/R/ta_RSI.R @@ -58,15 +58,15 @@ relative_strength_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ relative_strength_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ relative_strength_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( relative_strength_index.default( x = x, cols = cols, @@ -117,12 +117,38 @@ relative_strength_index.matrix <- function( na.bridge = FALSE, ... ) { - relative_strength_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + relative_strength_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases relative_strength_index +#' +#' @export +relative_strength_index.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + relative_strength_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ relative_strength_index.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ relative_strength_index.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -206,7 +237,7 @@ relative_strength_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -308,7 +339,7 @@ relative_strength_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_SAR.R b/R/ta_SAR.R index 7c39d7922..fb4565b3b 100644 --- a/R/ta_SAR.R +++ b/R/ta_SAR.R @@ -61,15 +61,15 @@ parabolic_stop_and_reverse.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -83,7 +83,7 @@ parabolic_stop_and_reverse.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -101,7 +101,7 @@ parabolic_stop_and_reverse.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( parabolic_stop_and_reverse.default( x = x, cols = cols, @@ -125,13 +125,41 @@ parabolic_stop_and_reverse.matrix <- function( na.bridge = FALSE, ... ) { - parabolic_stop_and_reverse.default( - x = x, - cols = cols, - accelerationFactor = accelerationFactor, - afMaximum = afMaximum, - na.bridge = na.bridge, - ... + as.matrix( + parabolic_stop_and_reverse.default( + x = x, + cols = cols, + accelerationFactor = accelerationFactor, + afMaximum = afMaximum, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases parabolic_stop_and_reverse +#' +#' @export +parabolic_stop_and_reverse.xts <- function( + x, + cols, + accelerationFactor = 0.02, + afMaximum = 0.2, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + parabolic_stop_and_reverse.default( + x = x, + cols = cols, + accelerationFactor = accelerationFactor, + afMaximum = afMaximum, + na.bridge = na.bridge, + ... + ) ) } @@ -180,7 +208,7 @@ parabolic_stop_and_reverse.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -286,7 +314,7 @@ parabolic_stop_and_reverse.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_SAREXT.R b/R/ta_SAREXT.R index 195a39fa1..a64c2ef23 100644 --- a/R/ta_SAREXT.R +++ b/R/ta_SAREXT.R @@ -79,15 +79,15 @@ extended_parabolic_stop_and_reverse.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -107,7 +107,7 @@ extended_parabolic_stop_and_reverse.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -131,7 +131,7 @@ extended_parabolic_stop_and_reverse.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( extended_parabolic_stop_and_reverse.default( x = x, cols = cols, @@ -167,19 +167,59 @@ extended_parabolic_stop_and_reverse.matrix <- function( na.bridge = FALSE, ... ) { - extended_parabolic_stop_and_reverse.default( - x = x, - cols = cols, - startValue = startValue, - offsetOnReverse = offsetOnReverse, - afInitLong = afInitLong, - afLong = afLong, - afMaxLong = afMaxLong, - afInitShort = afInitShort, - afShort = afShort, - afMaxShort = afMaxShort, - na.bridge = na.bridge, - ... + as.matrix( + extended_parabolic_stop_and_reverse.default( + x = x, + cols = cols, + startValue = startValue, + offsetOnReverse = offsetOnReverse, + afInitLong = afInitLong, + afLong = afLong, + afMaxLong = afMaxLong, + afInitShort = afInitShort, + afShort = afShort, + afMaxShort = afMaxShort, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases extended_parabolic_stop_and_reverse +#' +#' @export +extended_parabolic_stop_and_reverse.xts <- function( + x, + cols, + startValue = 0, + offsetOnReverse = 0, + afInitLong = 0.02, + afLong = 0.02, + afMaxLong = 0.2, + afInitShort = 0.02, + afShort = 0.02, + afMaxShort = 0.2, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + extended_parabolic_stop_and_reverse.default( + x = x, + cols = cols, + startValue = startValue, + offsetOnReverse = offsetOnReverse, + afInitLong = afInitLong, + afLong = afLong, + afMaxLong = afMaxLong, + afInitShort = afInitShort, + afShort = afShort, + afMaxShort = afMaxShort, + na.bridge = na.bridge, + ... + ) ) } @@ -246,7 +286,7 @@ extended_parabolic_stop_and_reverse.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) @@ -364,7 +404,7 @@ extended_parabolic_stop_and_reverse.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low, + formula.default = ~ high + low, ... ) diff --git a/R/ta_SMA.R b/R/ta_SMA.R index a62d2bc9e..14e111017 100644 --- a/R/ta_SMA.R +++ b/R/ta_SMA.R @@ -84,15 +84,15 @@ simple_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ simple_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ simple_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( simple_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ simple_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - simple_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + simple_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases simple_moving_average +#' +#' @export +simple_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + simple_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases simple_moving_average #' @@ -171,6 +198,10 @@ simple_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ simple_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ simple_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ simple_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_STDDEV.R b/R/ta_STDDEV.R index 611bed189..084463d71 100644 --- a/R/ta_STDDEV.R +++ b/R/ta_STDDEV.R @@ -47,6 +47,16 @@ rolling_standard_deviation.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -63,6 +73,7 @@ rolling_standard_deviation.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -97,6 +108,50 @@ rolling_standard_deviation.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_standard_deviation +#' +#' @export +rolling_standard_deviation.xts <- function( + x, + timePeriod = 5, + deviations = 1, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_STDDEV, + as.double(x), + as.integer(timePeriod), + as.double(deviations), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL STDDEV_lookback <- rollingStandardDeviation_lookback <- rolling_standard_deviation_lookback <- function( x, diff --git a/R/ta_STOCH.R b/R/ta_STOCH.R index 81303093c..aba28d837 100644 --- a/R/ta_STOCH.R +++ b/R/ta_STOCH.R @@ -63,15 +63,15 @@ stochastic.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -89,7 +89,7 @@ stochastic.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -110,7 +110,7 @@ stochastic.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( stochastic.default( x = x, cols = cols, @@ -140,16 +140,50 @@ stochastic.matrix <- function( na.bridge = FALSE, ... ) { - stochastic.default( - x = x, - cols = cols, - fastKPeriod = fastKPeriod, - slowKPeriod = slowKPeriod, - slowKMa = slowKMa, - slowDPeriod = slowDPeriod, - slowDMa = slowDMa, - na.bridge = na.bridge, - ... + as.matrix( + stochastic.default( + x = x, + cols = cols, + fastKPeriod = fastKPeriod, + slowKPeriod = slowKPeriod, + slowKMa = slowKMa, + slowDPeriod = slowDPeriod, + slowDMa = slowDMa, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases stochastic +#' +#' @export +stochastic.xts <- function( + x, + cols, + fastKPeriod = 5, + slowKPeriod = 3, + slowKMa = 0, + slowDPeriod = 3, + slowDMa = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + stochastic.default( + x = x, + cols = cols, + fastKPeriod = fastKPeriod, + slowKPeriod = slowKPeriod, + slowKMa = slowKMa, + slowDPeriod = slowDPeriod, + slowDMa = slowDMa, + na.bridge = na.bridge, + ... + ) ) } @@ -210,7 +244,7 @@ stochastic.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -321,7 +355,7 @@ stochastic.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_STOCHF.R b/R/ta_STOCHF.R index 8b7d58b7e..8c01ef110 100644 --- a/R/ta_STOCHF.R +++ b/R/ta_STOCHF.R @@ -64,15 +64,15 @@ fast_stochastic.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -88,7 +88,7 @@ fast_stochastic.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -107,7 +107,7 @@ fast_stochastic.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( fast_stochastic.default( x = x, cols = cols, @@ -133,14 +133,44 @@ fast_stochastic.matrix <- function( na.bridge = FALSE, ... ) { - fast_stochastic.default( - x = x, - cols = cols, - fastKPeriod = fastKPeriod, - fastDPeriod = fastDPeriod, - fastDMa = fastDMa, - na.bridge = na.bridge, - ... + as.matrix( + fast_stochastic.default( + x = x, + cols = cols, + fastKPeriod = fastKPeriod, + fastDPeriod = fastDPeriod, + fastDMa = fastDMa, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases fast_stochastic +#' +#' @export +fast_stochastic.xts <- function( + x, + cols, + fastKPeriod = 5, + fastDPeriod = 3, + fastDMa = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + fast_stochastic.default( + x = x, + cols = cols, + fastKPeriod = fastKPeriod, + fastDPeriod = fastDPeriod, + fastDMa = fastDMa, + na.bridge = na.bridge, + ... + ) ) } @@ -195,7 +225,7 @@ fast_stochastic.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -300,7 +330,7 @@ fast_stochastic.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_STOCHRSI.R b/R/ta_STOCHRSI.R index bfc927033..f2a51f7e7 100644 --- a/R/ta_STOCHRSI.R +++ b/R/ta_STOCHRSI.R @@ -66,15 +66,15 @@ stochastic_relative_strength_index.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -89,7 +89,7 @@ stochastic_relative_strength_index.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -109,7 +109,7 @@ stochastic_relative_strength_index.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( stochastic_relative_strength_index.default( x = x, cols = cols, @@ -137,15 +137,47 @@ stochastic_relative_strength_index.matrix <- function( na.bridge = FALSE, ... ) { - stochastic_relative_strength_index.default( - x = x, - cols = cols, - timePeriod = timePeriod, - fastKPeriod = fastKPeriod, - fastDPeriod = fastDPeriod, - fastDMa = fastDMa, - na.bridge = na.bridge, - ... + as.matrix( + stochastic_relative_strength_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + fastKPeriod = fastKPeriod, + fastDPeriod = fastDPeriod, + fastDMa = fastDMa, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases stochastic_relative_strength_index +#' +#' @export +stochastic_relative_strength_index.xts <- function( + x, + cols, + timePeriod = 14, + fastKPeriod = 5, + fastDPeriod = 3, + fastDMa = 0, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + stochastic_relative_strength_index.default( + x = x, + cols = cols, + timePeriod = timePeriod, + fastKPeriod = fastKPeriod, + fastDPeriod = fastDPeriod, + fastDMa = fastDMa, + na.bridge = na.bridge, + ... + ) ) } @@ -191,6 +223,10 @@ stochastic_relative_strength_index.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -206,6 +242,7 @@ stochastic_relative_strength_index.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -244,7 +281,7 @@ stochastic_relative_strength_index.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -350,7 +387,7 @@ stochastic_relative_strength_index.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_SUM.R b/R/ta_SUM.R index ab4ea9813..603f5b56a 100644 --- a/R/ta_SUM.R +++ b/R/ta_SUM.R @@ -45,6 +45,16 @@ rolling_sum.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -60,6 +70,7 @@ rolling_sum.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -92,6 +103,48 @@ rolling_sum.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_sum +#' +#' @export +rolling_sum.xts <- function( + x, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_SUM, + as.double(x), + as.integer(timePeriod), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL SUM_lookback <- rollingSum_lookback <- rolling_sum_lookback <- function( x, diff --git a/R/ta_T3.R b/R/ta_T3.R index fe39a1a3a..5c365bac5 100644 --- a/R/ta_T3.R +++ b/R/ta_T3.R @@ -91,15 +91,15 @@ t3_exponential_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -112,7 +112,7 @@ t3_exponential_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -130,7 +130,7 @@ t3_exponential_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( t3_exponential_moving_average.default( x = x, cols = cols, @@ -154,16 +154,45 @@ t3_exponential_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - t3_exponential_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - volumeFactor = volumeFactor, - na.bridge = na.bridge, - ... + as.matrix( + t3_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + volumeFactor = volumeFactor, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases t3_exponential_moving_average +#' +#' @export +t3_exponential_moving_average.xts <- function( + x, + cols, + timePeriod = 5, + volumeFactor = 0.7, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + t3_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + volumeFactor = volumeFactor, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases t3_exponential_moving_average #' @@ -184,6 +213,10 @@ t3_exponential_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -197,6 +230,7 @@ t3_exponential_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -245,7 +279,7 @@ t3_exponential_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -316,7 +350,7 @@ t3_exponential_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_TEMA.R b/R/ta_TEMA.R index 4ee93b851..b39fdf272 100644 --- a/R/ta_TEMA.R +++ b/R/ta_TEMA.R @@ -84,15 +84,15 @@ triple_exponential_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ triple_exponential_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ triple_exponential_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( triple_exponential_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ triple_exponential_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - triple_exponential_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + triple_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases triple_exponential_moving_average +#' +#' @export +triple_exponential_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + triple_exponential_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases triple_exponential_moving_average #' @@ -171,6 +198,10 @@ triple_exponential_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ triple_exponential_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ triple_exponential_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ triple_exponential_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_TRANGE.R b/R/ta_TRANGE.R index baf6750c5..4ac16895e 100644 --- a/R/ta_TRANGE.R +++ b/R/ta_TRANGE.R @@ -56,15 +56,15 @@ true_range.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -77,7 +77,7 @@ true_range.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -93,7 +93,7 @@ true_range.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( true_range.default( x = x, cols = cols, @@ -113,11 +113,35 @@ true_range.matrix <- function( na.bridge = FALSE, ... ) { - true_range.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + true_range.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases true_range +#' +#' @export +true_range.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + true_range.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } @@ -161,7 +185,7 @@ true_range.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -252,7 +276,7 @@ true_range.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_TRIMA.R b/R/ta_TRIMA.R index f891f7f90..c70940f6b 100644 --- a/R/ta_TRIMA.R +++ b/R/ta_TRIMA.R @@ -84,15 +84,15 @@ triangular_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ triangular_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ triangular_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( triangular_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ triangular_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - triangular_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + triangular_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases triangular_moving_average +#' +#' @export +triangular_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + triangular_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases triangular_moving_average #' @@ -171,6 +198,10 @@ triangular_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ triangular_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ triangular_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ triangular_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_TRIX.R b/R/ta_TRIX.R index 19c8a6b77..a72511251 100644 --- a/R/ta_TRIX.R +++ b/R/ta_TRIX.R @@ -58,15 +58,15 @@ triple_exponential_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula = cols, + formula.default = ~close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -78,7 +78,7 @@ triple_exponential_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -95,7 +95,7 @@ triple_exponential_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( triple_exponential_average.default( x = x, cols = cols, @@ -117,12 +117,38 @@ triple_exponential_average.matrix <- function( na.bridge = FALSE, ... ) { - triple_exponential_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + triple_exponential_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases triple_exponential_average +#' +#' @export +triple_exponential_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + triple_exponential_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -159,6 +185,10 @@ triple_exponential_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -171,6 +201,7 @@ triple_exponential_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -204,7 +235,7 @@ triple_exponential_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +328,7 @@ triple_exponential_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/ta_TYPPRICE.R b/R/ta_TYPPRICE.R index 03bf1d156..6378e3e4e 100644 --- a/R/ta_TYPPRICE.R +++ b/R/ta_TYPPRICE.R @@ -56,15 +56,15 @@ typical_price.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -77,7 +77,7 @@ typical_price.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -93,7 +93,7 @@ typical_price.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( typical_price.default( x = x, cols = cols, @@ -113,11 +113,35 @@ typical_price.matrix <- function( na.bridge = FALSE, ... ) { - typical_price.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + typical_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases typical_price +#' +#' @export +typical_price.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + typical_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } diff --git a/R/ta_ULTOSC.R b/R/ta_ULTOSC.R index 270785429..bb31b6449 100644 --- a/R/ta_ULTOSC.R +++ b/R/ta_ULTOSC.R @@ -64,15 +64,15 @@ ultimate_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -88,7 +88,7 @@ ultimate_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -107,7 +107,7 @@ ultimate_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ultimate_oscillator.default( x = x, cols = cols, @@ -133,14 +133,44 @@ ultimate_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - ultimate_oscillator.default( - x = x, - cols = cols, - firstPeriod = firstPeriod, - secondPeriod = secondPeriod, - thirdPeriod = thirdPeriod, - na.bridge = na.bridge, - ... + as.matrix( + ultimate_oscillator.default( + x = x, + cols = cols, + firstPeriod = firstPeriod, + secondPeriod = secondPeriod, + thirdPeriod = thirdPeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases ultimate_oscillator +#' +#' @export +ultimate_oscillator.xts <- function( + x, + cols, + firstPeriod = 7, + secondPeriod = 14, + thirdPeriod = 28, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + ultimate_oscillator.default( + x = x, + cols = cols, + firstPeriod = firstPeriod, + secondPeriod = secondPeriod, + thirdPeriod = thirdPeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -195,7 +225,7 @@ ultimate_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -303,7 +333,7 @@ ultimate_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_VAR.R b/R/ta_VAR.R index 43d77c849..11d09c4f0 100644 --- a/R/ta_VAR.R +++ b/R/ta_VAR.R @@ -47,6 +47,16 @@ rolling_variance.default <- function( na.bridge = FALSE, ... ) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + ## calculate indicator and ## return as data.frame x <- .Call( @@ -63,6 +73,7 @@ rolling_variance.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -97,6 +108,50 @@ rolling_variance.numeric <- function( x } +#' @usage NULL +#' @aliases rolling_variance +#' +#' @export +rolling_variance.xts <- function( + x, + timePeriod = 5, + deviations = 1, + na.bridge = FALSE, + ... +) { + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + assert( + x = NCOL(x) == 1L, + call = sys.call(sys.parent()), + "Expected 'x' to be univariate.", + paste0("Got ", NCOL(x), " columns.") + ) + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_VAR, + as.double(x), + as.integer(timePeriod), + as.double(deviations), + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL VAR_lookback <- rollingVariance_lookback <- rolling_variance_lookback <- function( x, diff --git a/R/ta_VOLUME.R b/R/ta_VOLUME.R index 89da85349..a2ce84d1e 100644 --- a/R/ta_VOLUME.R +++ b/R/ta_VOLUME.R @@ -58,15 +58,15 @@ trading_volume.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ volume + open + close, - data = x, + x = x, + formula.default = ~ volume + open + close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -87,7 +87,7 @@ trading_volume.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -126,12 +126,38 @@ trading_volume.matrix <- function( na.bridge = FALSE, ... ) { - trading_volume.default( - x = x, - cols = cols, - maType = maType, - na.bridge = na.bridge, - ... + as.matrix( + trading_volume.default( + x = x, + cols = cols, + maType = maType, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases trading_volume +#' +#' @export +trading_volume.xts <- function( + x, + cols, + maType = list(SMA(timePeriod = 7), SMA(timePeriod = 15)), + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + trading_volume.default( + x = x, + cols = cols, + maType = maType, + na.bridge = na.bridge, + ... + ) ) } @@ -155,13 +181,24 @@ trading_volume.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( C_impl_ta_VOLUME, ## splice:numeric:start as.double(x), - maType, + lapply( + maType, + function(x) { + as.integer( + x + ) + } + ), ## splice:numeric:end as.logical(na.bridge) ) @@ -169,6 +206,7 @@ trading_volume.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -203,7 +241,7 @@ trading_volume.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ volume + open + close, + formula.default = ~ volume + open + close, ... ) @@ -339,7 +377,7 @@ trading_volume.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ volume + open + close, + formula.default = ~ volume + open + close, ... ) diff --git a/R/ta_VWMA.R b/R/ta_VWMA.R index 7e77bb4ca..79598c003 100644 --- a/R/ta_VWMA.R +++ b/R/ta_VWMA.R @@ -84,15 +84,15 @@ volume_weighted_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ close + volume, - data = x, + x = x, + formula.default = ~ close + volume, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -105,7 +105,7 @@ volume_weighted_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -122,7 +122,7 @@ volume_weighted_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( volume_weighted_moving_average.default( x = x, cols = cols, @@ -144,15 +144,42 @@ volume_weighted_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - volume_weighted_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + volume_weighted_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases volume_weighted_moving_average +#' +#' @export +volume_weighted_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + volume_weighted_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases volume_weighted_moving_average #' @@ -172,6 +199,10 @@ volume_weighted_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -184,6 +215,7 @@ volume_weighted_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -229,7 +261,7 @@ volume_weighted_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) @@ -298,7 +330,7 @@ volume_weighted_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ close + volume, + formula.default = ~ close + volume, ... ) diff --git a/R/ta_WCLPRICE.R b/R/ta_WCLPRICE.R index 22243ef6f..89da79e79 100644 --- a/R/ta_WCLPRICE.R +++ b/R/ta_WCLPRICE.R @@ -56,15 +56,15 @@ weighted_close_price.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -77,7 +77,7 @@ weighted_close_price.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -93,7 +93,7 @@ weighted_close_price.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( weighted_close_price.default( x = x, cols = cols, @@ -113,11 +113,35 @@ weighted_close_price.matrix <- function( na.bridge = FALSE, ... ) { - weighted_close_price.default( - x = x, - cols = cols, - na.bridge = na.bridge, - ... + as.matrix( + weighted_close_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases weighted_close_price +#' +#' @export +weighted_close_price.xts <- function( + x, + cols, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + weighted_close_price.default( + x = x, + cols = cols, + na.bridge = na.bridge, + ... + ) ) } diff --git a/R/ta_WILLR.R b/R/ta_WILLR.R index 9e667108c..489fbdc22 100644 --- a/R/ta_WILLR.R +++ b/R/ta_WILLR.R @@ -58,15 +58,15 @@ williams_oscillator.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~ high + low + close, - data = x, + x = x, + formula = cols, + formula.default = ~ high + low + close, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -80,7 +80,7 @@ williams_oscillator.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -97,7 +97,7 @@ williams_oscillator.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( williams_oscillator.default( x = x, cols = cols, @@ -119,12 +119,38 @@ williams_oscillator.matrix <- function( na.bridge = FALSE, ... ) { - williams_oscillator.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + williams_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases williams_oscillator +#' +#' @export +williams_oscillator.xts <- function( + x, + cols, + timePeriod = 14, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + williams_oscillator.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } @@ -173,7 +199,7 @@ williams_oscillator.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) @@ -272,7 +298,7 @@ williams_oscillator.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~ high + low + close, + formula.default = ~ high + low + close, ... ) diff --git a/R/ta_WMA.R b/R/ta_WMA.R index 50b8d38ba..abbc429f3 100644 --- a/R/ta_WMA.R +++ b/R/ta_WMA.R @@ -84,15 +84,15 @@ weighted_moving_average.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ~close, - data = x, + x = x, + formula.default = ~close, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -104,7 +104,7 @@ weighted_moving_average.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -121,7 +121,7 @@ weighted_moving_average.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( weighted_moving_average.default( x = x, cols = cols, @@ -143,15 +143,42 @@ weighted_moving_average.matrix <- function( na.bridge = FALSE, ... ) { - weighted_moving_average.default( - x = x, - cols = cols, - timePeriod = timePeriod, - na.bridge = na.bridge, - ... + as.matrix( + weighted_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) + ) +} + +#' @usage NULL +#' @aliases weighted_moving_average +#' +#' @export +weighted_moving_average.xts <- function( + x, + cols, + timePeriod = 30, + na.bridge = FALSE, + ... +) { + assert_xts() + + as.xts( + weighted_moving_average.default( + x = x, + cols = cols, + timePeriod = timePeriod, + na.bridge = na.bridge, + ... + ) ) } + #' @usage NULL #' @aliases weighted_moving_average #' @@ -171,6 +198,10 @@ weighted_moving_average.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -183,6 +214,7 @@ weighted_moving_average.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } @@ -228,7 +260,7 @@ weighted_moving_average.plotly <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) @@ -297,7 +329,7 @@ weighted_moving_average.ggplot <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ~close, + formula.default = ~close, ... ) diff --git a/R/utils.R b/R/utils.R index 74b1febe3..f0cfb2db4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -67,6 +67,20 @@ assert_plotly_object <- function(x) { ) } +## assert_xts(): assert that the xts PACKAGE is installed, and load +## its namespace so the [.xts / index machinery is registered even in +## sessions that never attached xts (deserialized objects, LazyData +## fixtures like GOOGL). Mirrors assert_plotly_pkg()/assert_ggplot2(). +assert_xts <- function() { + if (!requireNamespace("xts", quietly = TRUE)) { + stop( + "Package 'xts' is required for input. ", + "Install it with install.packages('xts').", + call. = FALSE + ) + } +} + assert_column_names <- function(formula, available_variables) { ## this assert function will give an error ## if the variables are not found. If it finds @@ -152,6 +166,11 @@ assert_column_names <- function(formula, available_variables) { x } +## base::nullfile() exists only from R 4.0 +.nullfile <- function() { + if (.Platform$OS.type == "windows") "nul:" else "/dev/null" +} + ## class related utility ## functions is.formula <- function(x) { @@ -298,6 +317,69 @@ candlestick_setting <- function() { invisible(NULL) } +index <- function(x) { + UseMethod("index") +} + +#' @export +index.default <- function(x) { + rownames(x) +} + +#' @export +index.xts <- function(x) { + attr( + x = x, + which = "index" + ) +} + +## Index +set_index <- function(x, value) { + UseMethod("set_index", object = value) +} + +#' @export +set_index.default <- function(x, value) { + stop( + "Cannot set the index from <", + class(value)[1L], + ">. Expected rownames or a -index.", + call. = FALSE + ) +} + +#' @export +set_index.character <- function(x, value) { + if (is.matrix(x)) { + .Call( + C_index_matrix, + x, + value, + colnames(x) + ) + } else { + ## set the rownames + .Call( + C_index_data_frame, + x, + value + ) + } + + return(invisible(NULL)) +} + +#' @export +set_index.numeric <- function(x, value) { + .Call( + C_index_xts, + x, + value + ) + + return(invisible(NULL)) +} ## rownaming set_rownames <- function(x, x_names) { @@ -308,7 +390,7 @@ set_rownames <- function(x, x_names) { set_rownames.data.frame <- function(x, x_names) { ## set the rownames .Call( - C_rownames_data_frame, + C_index_data_frame, x, x_names ) @@ -320,7 +402,7 @@ set_rownames.data.frame <- function(x, x_names) { set_rownames.matrix <- function(x, x_names) { ## set the rownames .Call( - C_rownames_matrix, + C_index_matrix, x, x_names, colnames(x) @@ -329,11 +411,49 @@ set_rownames.matrix <- function(x, x_names) { return(invisible(NULL)) } +#' @export +as.data.frame.ta_object <- function(x, row.names, optional, ...) { + ## extract 'lookback' attribute + lookback_attribute <- attr(x, "lookback", TRUE) + + if (is.matrix(x)) { + if (is.double(x)) { + x <- .Call( + C_map_dfr_double, + x + ) + } + if (is.integer(x)) { + x <- .Call( + C_map_dfr_integer, + x + ) + } + } + + attr(x, "lookback") <- lookback_attribute + + return(x) +} + +#' @export +as.matrix.ta_object <- function(x, ...) { + class(x) <- c("matrix", "array") + + return(x) +} + + ## map to map_dfr <- function(x) { UseMethod("map_dfr") } +#' @export +map_dfr.ta_object <- function(x) { + as.data.frame(x) +} + #' @export map_dfr.double <- function(x) { if (!is.matrix(x)) { @@ -403,3 +523,13 @@ as.maType.double <- function(x, ...) { #' @export as.maType.integer <- as.maType.double + +as.xts <- function(x) { + UseMethod("as.xts") +} + +#' @export +as.xts.ta_object <- function(x) { + class(x) <- c("xts", "zoo") + x +} diff --git a/README.md b/README.md index eea0fdf6a..73da97bf3 100644 --- a/README.md +++ b/README.md @@ -63,28 +63,36 @@ pak::pak("serkor1/ta-lib-R") ## Quick start -All functions provide S3 methods for ``, ``, -and—where applicable—`` inputs. The general convention is -simple: the output uses the same container type as the input. +All functions provide S3 methods for ``, ``, +``, and—where applicable—`` inputs. The general +convention is simple: the output uses the same container type as the +input. ``` r ## calculate the ## relative strength index relative_strength_index <- talib::RSI( - talib::BTC + talib::GOOGL ) +## check class equivalence +inherits( + relative_strength_index, + class(talib::GOOGL) +) +#> [1] TRUE + ## display results tail( relative_strength_index ) -#> RSI -#> 2024-12-26 01:00:00 46.48851 -#> 2024-12-27 01:00:00 43.85488 -#> 2024-12-28 01:00:00 45.93888 -#> 2024-12-29 01:00:00 43.12301 -#> 2024-12-30 01:00:00 41.47686 -#> 2024-12-31 01:00:00 43.37358 +#> RSI +#> 2021-12-22 53.47421 +#> 2021-12-23 54.45979 +#> 2021-12-27 56.42226 +#> 2021-12-28 53.37121 +#> 2021-12-29 53.28979 +#> 2021-12-30 52.07450 ``` Indicator outputs preserve input length, which keeps results aligned @@ -94,19 +102,19 @@ with the original OHLCV rows. ## combine multiple ## indicators features <- cbind( - talib::relative_strength_index(talib::BTC), - talib::bollinger_bands(talib::BTC), - talib::engulfing(talib::BTC) + talib::relative_strength_index(talib::GOOGL), + talib::bollinger_bands(talib::GOOGL), + talib::engulfing(talib::GOOGL) ) tail(features) -#> RSI UpperBand MiddleBand LowerBand CDLENGULFING -#> 2024-12-26 01:00:00 46.48851 106053.7 99594.80 93135.86 -100 -#> 2024-12-27 01:00:00 43.85488 106179.5 99305.69 92431.90 0 -#> 2024-12-28 01:00:00 45.93888 106051.3 99002.74 91954.18 0 -#> 2024-12-29 01:00:00 43.12301 106223.8 98814.94 91406.11 -100 -#> 2024-12-30 01:00:00 41.47686 106452.7 98613.30 90773.93 0 -#> 2024-12-31 01:00:00 43.37358 106283.3 98223.05 90162.77 0 +#> RSI UpperBand MiddleBand LowerBand CDLENGULFING +#> 2021-12-22 53.47421 149.1432 144.4920 139.8408 0 +#> 2021-12-23 54.45979 149.2513 144.5318 139.8124 0 +#> 2021-12-27 56.42226 149.6263 144.8180 140.0097 0 +#> 2021-12-28 53.37121 149.7444 144.8758 140.0072 -100 +#> 2021-12-29 53.28979 149.8398 145.1137 140.3876 0 +#> 2021-12-30 52.07450 149.7308 145.3711 141.0115 -100 ``` ## Charting @@ -118,16 +126,16 @@ flexibility: ``` r ## subset data and -## store as 'BTC' -BTC <- talib::BTC[1:75, ] +## store as 'GOOGL' +GOOGL <- talib::GOOGL[1:75, ] ## construct chart in a brace block ## alternatively use `|>` { ## initialize main chart talib::chart( - x = BTC, - title = "Bitcoin" + x = GOOGL, + title = "Alphabet Inc." ) ## add Bollinger Bands to diff --git a/_pkgdown.yml b/_pkgdown.yml index fbcda687d..ee8244ed4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -90,4 +90,5 @@ reference: - SPY - NVDA - ATOM + - GOOGL diff --git a/codegen/src/render.rs b/codegen/src/render.rs index 761db2116..26db9ec0a 100644 --- a/codegen/src/render.rs +++ b/codegen/src/render.rs @@ -360,6 +360,19 @@ pub fn render_indicator(f: &MetaData, t: &Templates) -> String { .collect::>() .join("\n\t\t"); + // the univariate guard of the rolling .default/.xts methods: + // one assert per input series, rejecting multi-column input + // instead of flattening it column-major + let series_guard = series + .iter() + .map(|s| { + format!( + "assert(\n\t\tx = NCOL({s}) == 1L,\n\t\tcall = sys.call(sys.parent()),\n\t\t\"Expected '{s}' to be univariate.\",\n\t\tpaste0(\"Got \", NCOL({s}), \" columns.\")\n\t)" + ) + }) + .collect::>() + .join("\n\n\t"); + let c_numeric = series .iter() .map(|s| format!("as.double({s})")) @@ -412,6 +425,7 @@ pub fn render_indicator(f: &MetaData, t: &Templates) -> String { .replace("${C_SIGNATURE}", &c_signature) .replace("${C_NUMERIC}", &c_numeric) .replace("${SERIES}", &series_args) + .replace("${SERIES_GUARD}", &series_guard) .replace("${PSERIES}", &pseries) .replace("${SPEC_FIELDS}", &spec_fields) .replace("${MA_TYPE}", ma_index.unwrap_or("-1L")) diff --git a/codegen/src/testthat.rs b/codegen/src/testthat.rs index 0de023e74..e5fcbf89c 100644 --- a/codegen/src/testthat.rs +++ b/codegen/src/testthat.rs @@ -86,6 +86,29 @@ testthat::expect_equal( } ) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- ${FUN}(x = GOOGL[, 1]${ADDITIONAL_XTS}) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(${FUN}(x = as.numeric(GOOGL[, 1])${ADDITIONAL_NUMERIC})) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(${FUN}(x = GOOGL${ADDITIONAL_XTS})) + testthat::expect_error(${FUN}(x = SPY${ADDITIONAL})) +}) "#; const STANDARD_TESTS: &str = r#" @@ -141,6 +164,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(${FUN}(GOOGL${PASS_GOOGL}), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(${FUN}(reference${PASS_GOOGL}))) + + testthat::expect_equal( + object = unname(zoo::coredata(${FUN}(GOOGL${PASS_GOOGL}))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(${FUN}(GOOGL[, sort(colnames(GOOGL))]${PASS_GOOGL}))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -260,8 +319,8 @@ testthat::expect_equal( #camel### the camelCase lookback alias #camel### is the function itself #camel#testthat::expect_identical( -#camel# object = ${CAMEL}_lookback, -#camel# expected = ${FUN}_lookback +#camel# object = talib:::${CAMEL}_lookback, +#camel# expected = talib:::${FUN}_lookback #camel# ) } @@ -373,9 +432,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) @@ -388,12 +449,23 @@ pub fn render_test(f: &MetaData) -> String { // rolling statistics fast-track: a short univariate file, // with the second input series of BETA/CORREL passed as 'y' if f.family == "Statistic Functions" || f.family == "Math Operators" { - let additional = if f.input.len() > 1 { ",y=SPY[,2]" } else { "" }; - + let bivariate = f.input.len() > 1; + let additional = if bivariate { ",y=SPY[,2]" } else { "" }; + let additional_xts = if bivariate { ", y = GOOGL[, 2]" } else { "" }; + let additional_numeric = if bivariate { + ", y = as.numeric(GOOGL[, 2])" + } else { + "" + }; + + // ${ADDITIONAL} is a prefix of the two variants: + // replace the longer placeholders first return format!( "{HEADER}{}", ROLLING_TESTS .replace("${FUN}", fun) + .replace("${ADDITIONAL_XTS}", additional_xts) + .replace("${ADDITIONAL_NUMERIC}", additional_numeric) .replace("${ADDITIONAL}", additional) ); } @@ -422,6 +494,7 @@ pub fn render_test(f: &MetaData) -> String { .replace("${PASS_SPY}", &pass("SPY")) .replace("${PASS_BTC}", &pass("BTC")) .replace("${PASS_ATOM}", &pass("ATOM")) + .replace("${PASS_GOOGL}", &pass("GOOGL")) }; let mut out = format!("{HEADER}{}", fill(STANDARD_TESTS)); @@ -465,12 +538,14 @@ mod tests { assert!(rendered.contains("output <- bollinger_bands(SPY)")); assert!(rendered.contains("alias <- BBANDS(SPY)")); assert!(rendered.contains("camel <- bollingerBands(SPY)")); - assert!(rendered.contains("object = bollingerBands_lookback,")); + assert!(rendered.contains("object = talib:::bollingerBands_lookback,")); assert!(!rendered.contains("#camel#"), "unstripped camel prefix"); assert!(rendered.contains("cols = ~close")); assert!(rendered.contains("-methods for ")); assert!(rendered.contains("-methods for ")); assert!(rendered.contains(" methods")); + assert!(rendered.contains("Value parity with ()")); + assert!(rendered.contains(r#"skip_if_not_installed("xts")"#)); assert!(!rendered.contains("${"), "unreplaced placeholder"); } @@ -525,9 +600,20 @@ mod tests { assert!(!rendered.contains("y=SPY[,2]")); assert!(!rendered.contains("Alias and function similarity")); + // the xts blocks: class round-trip with value parity + // against the vector path, and the multivariate guard + assert!(rendered.contains("Class in, class out ()")); + assert!(rendered.contains("Multivariate input errors")); + assert!(rendered.contains("x = GOOGL[, 1])")); + assert!(!rendered.contains("y = GOOGL[, 2]")); + assert!(!rendered.contains("${"), "unreplaced placeholder"); + // the bivariate rolling statistics pass // the second column as 'y' let rendered = render_test(&meta("BETA", "Statistic Functions", &["close", "close"])); assert!(rendered.contains("x = SPY[,1],y=SPY[,2]")); + assert!(rendered.contains("x = GOOGL[, 1], y = GOOGL[, 2]")); + assert!(rendered.contains("y = as.numeric(GOOGL[, 2])")); + assert!(!rendered.contains("${"), "unreplaced placeholder"); } } diff --git a/codegen/templates/candlestick_template.R b/codegen/templates/candlestick_template.R index e0733a682..1daea598c 100644 --- a/codegen/templates/candlestick_template.R +++ b/codegen/templates/candlestick_template.R @@ -78,32 +78,30 @@ ${FUN}.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ${FORMULA}, - data = x, + x = x, + formula.default = ${FORMULA}, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame - x <- as.matrix( - .Call( + x <- .Call( C_impl_ta_${ALIAS}, ${C_SIGNATURE}, normalize, as.logical(na.bridge) ) - ) ## add column name colnames(x) <- "${ALIAS}" ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -120,7 +118,7 @@ ${FUN}.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ${FUN}.default( x = x, cols = cols, @@ -142,16 +140,44 @@ ${FUN}.matrix <- function( ${ARGS} na.bridge = FALSE, ...) { - - ${FUN}.default( + as.matrix( +${FUN}.default( x = x, cols = cols , ${PARGS} na.bridge = na.bridge, ... ) + ) + +} + +#' @usage NULL +#' @aliases ${FUN} +#' +#' @export +${FUN}.xts <- function( + x, + cols, + ${ARGS} + na.bridge = FALSE, + ...) { + + assert_xts() + + as.xts( + ${FUN}.default( + x = x, + cols = cols, + ${PARGS} + na.bridge = na.bridge, + ... + ) + ) + } + #' @usage NULL ${ALIAS}_lookback <- ${CAMEL_LOOKBACK}${FUN}_lookback <- function( x, diff --git a/codegen/templates/chart_candlestick_template.R b/codegen/templates/chart_candlestick_template.R index 7d05e32dc..a1160044b 100644 --- a/codegen/templates/chart_candlestick_template.R +++ b/codegen/templates/chart_candlestick_template.R @@ -26,7 +26,7 @@ ${FUN}.${METHOD} <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ${FORMULA}, + formula.default = ${FORMULA}, ... ) diff --git a/codegen/templates/chart_main_template.R b/codegen/templates/chart_main_template.R index 3d1eda9b1..34752042a 100644 --- a/codegen/templates/chart_main_template.R +++ b/codegen/templates/chart_main_template.R @@ -28,7 +28,7 @@ ${FUN}.${METHOD} <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ${FORMULA}, + formula.default = ${FORMULA}, ... ) diff --git a/codegen/templates/chart_moving_average_template.R b/codegen/templates/chart_moving_average_template.R index 977f9de4d..b01315a24 100644 --- a/codegen/templates/chart_moving_average_template.R +++ b/codegen/templates/chart_moving_average_template.R @@ -26,7 +26,7 @@ ${FUN}.${METHOD} <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ${FORMULA}, + formula.default = ${FORMULA}, ... ) diff --git a/codegen/templates/chart_subchart_template.R b/codegen/templates/chart_subchart_template.R index 1a43471e4..624f6587c 100644 --- a/codegen/templates/chart_subchart_template.R +++ b/codegen/templates/chart_subchart_template.R @@ -32,7 +32,7 @@ ${FUN}.${METHOD} <- function( constructed_series <- series( x = x, formula = cols, - default_formula = ${FORMULA}, + formula.default = ${FORMULA}, ... ) diff --git a/codegen/templates/indicator_template.R b/codegen/templates/indicator_template.R index f0b947dc9..74f7298e2 100644 --- a/codegen/templates/indicator_template.R +++ b/codegen/templates/indicator_template.R @@ -57,15 +57,15 @@ ${FUN}.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ${FORMULA}, - data = x, + x = x, + formula = cols, + formula.default = ${FORMULA}, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -76,7 +76,7 @@ ${FUN}.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -93,7 +93,7 @@ ${FUN}.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ${FUN}.default( x = x, cols = cols, @@ -115,14 +115,41 @@ ${FUN}.matrix <- function( ${ARGS} na.bridge = FALSE, ...) { - - ${FUN}.default( + as.matrix( +${FUN}.default( x = x, cols = cols , ${PARGS} na.bridge = na.bridge, ... ) + ) + +} + +#' @usage NULL +#' @aliases ${FUN} +#' +#' @export +${FUN}.xts <- function( + x, + cols, + ${ARGS} + na.bridge = FALSE, + ...) { + + assert_xts() + + as.xts( + ${FUN}.default( + x = x, + cols = cols, + ${PARGS} + na.bridge = na.bridge, + ... + ) + ) + } #' @usage NULL diff --git a/codegen/templates/moving_average_template.R b/codegen/templates/moving_average_template.R index 19b9561f8..e8c4995ef 100644 --- a/codegen/templates/moving_average_template.R +++ b/codegen/templates/moving_average_template.R @@ -80,15 +80,15 @@ ${FUN}.default <- function( ## construct series ## from input constructed_series <- series( - x = cols, - default_formula = ${FORMULA}, - data = x, + x = x, + formula.default = ${FORMULA}, + formula = cols, ... ) ## extract rownames ## for later attachment - x_names <- rownames(constructed_series) + x_names <- index(constructed_series) ## calculate indicator and ## return as data.frame @@ -99,7 +99,7 @@ ${FUN}.default <- function( ) ## readd rownames - set_rownames(x, x_names) + set_index(x, x_names) ## return indicator x @@ -116,7 +116,7 @@ ${FUN}.data.frame <- function( na.bridge = FALSE, ... ) { - map_dfr( + as.data.frame( ${FUN}.default( x = x, cols = cols, @@ -138,16 +138,44 @@ ${FUN}.matrix <- function( ${ARGS} na.bridge = FALSE, ...) { - - ${FUN}.default( +as.matrix( +${FUN}.default( x = x, cols = cols , ${PARGS} na.bridge = na.bridge, ... ) +) + +} + +#' @usage NULL +#' @aliases ${FUN} +#' +#' @export +${FUN}.xts <- function( + x, + cols, + ${ARGS} + na.bridge = FALSE, + ...) { + + assert_xts() + + as.xts( + ${FUN}.default( + x = x, + cols = cols, + ${PARGS} + na.bridge = na.bridge, + ... + ) + ) + } + #' @usage NULL #' @aliases ${FUN} #' @@ -167,6 +195,10 @@ ${FUN}.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass to 'C' directly ## with the input vector x <- .Call( @@ -178,6 +210,7 @@ ${FUN}.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } diff --git a/codegen/templates/numeric_template.R b/codegen/templates/numeric_template.R index f96709b0d..8285ff769 100644 --- a/codegen/templates/numeric_template.R +++ b/codegen/templates/numeric_template.R @@ -17,6 +17,10 @@ ${FUN}.numeric <- function( warning("'cols' is passed but is unused for vectors.") } + if (...length()) { + warning("'...' is passed but is unused for vectors.") + } + ## pass the argument directly ## to 'C' x <- .Call( @@ -28,6 +32,7 @@ ${FUN}.numeric <- function( if (dim(x)[2] == 1L) { dim(x) <- NULL } + class(x) <- NULL x } diff --git a/codegen/templates/rolling_template.R b/codegen/templates/rolling_template.R index 3ba503292..7abbbe66f 100644 --- a/codegen/templates/rolling_template.R +++ b/codegen/templates/rolling_template.R @@ -42,12 +42,17 @@ ${FUN}.default <- function( ${ARGS} na.bridge = FALSE, ...) { + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + ${SERIES_GUARD} + ## calculate indicator and ## return as data.frame x <- .Call( C_impl_ta_${ALIAS}, ## splice:call:start - ${C_NUMERIC},,, + ${C_NUMERIC}, ## splice:call:end as.logical(na.bridge) ) @@ -56,6 +61,7 @@ ${FUN}.default <- function( ## while preserving ## attributes dim(x) <- NULL + class(x) <- NULL ## return indicator x @@ -87,6 +93,41 @@ ${FUN}.numeric <- function( x } +#' @usage NULL +#' @aliases ${FUN} +#' +#' @export +${FUN}.xts <- function( + ${SERIES} + ${ARGS} + na.bridge = FALSE, ...) { + + assert_xts() + + ## rolling statistics are univariate - + ## multi-column input is rejected instead + ## of being flattened column-major + ${SERIES_GUARD} + + ## extract the index + ## for later attachment + x_names <- index(x) + + ## calculate indicator and + ## return as + x <- .Call( + C_impl_ta_${ALIAS}, + ${C_NUMERIC}, + as.logical(na.bridge) + ) + + ## readd the index + set_index(x, x_names) + + ## return indicator + as.xts(x) +} + #' @usage NULL ${ALIAS}_lookback <- ${CAMEL_LOOKBACK}${FUN}_lookback <- function( x,${ARGS} diff --git a/data-raw/GOOGL.R b/data-raw/GOOGL.R new file mode 100644 index 000000000..ab36a311e --- /dev/null +++ b/data-raw/GOOGL.R @@ -0,0 +1,18 @@ +## script: GOOGL +## objective: Generate GOOGL +## data for the R package +## using {quantmod} +## +## 1) load data +GOOGL <- quantmod::getSymbols( + Symbols = "GOOGL", + auto.assign = FALSE, + from = as.Date("2019-01-01"), + to = as.Date("2021-12-31") +) + +## 2) store data +usethis::use_data( + GOOGL, + overwrite = TRUE +) diff --git a/data/GOOGL.rda b/data/GOOGL.rda new file mode 100644 index 000000000..71f9c3431 Binary files /dev/null and b/data/GOOGL.rda differ diff --git a/dev/README.Rmd b/dev/README.Rmd index ce73cb185..0089feea7 100644 --- a/dev/README.Rmd +++ b/dev/README.Rmd @@ -46,12 +46,11 @@ The API covers 150+ [TA-Lib](https://github.com/TA-Lib/ta-lib)-backed functions | Need | {talib}| |:----------------------|:-----------------------------------------------------------------------------------------| -| Technical indicators | TA-Lib-backed moving averages, momentum, volatility, volume, cycle, and overlap studies | -| Candlestick patterns | Built-in Japanese candlestick pattern recognition | -| OHLCV workflows | Works directly with open, high, low, close, and volume columns | -| Performance | Computation delegated to C routines through `.Call()` | -| Dependencies | Minimal required R dependencies; plotting packages are optional | -| Charts | Composable financial charts with optional `{plotly}` and `{ggplot2}` support | +| Technical indicators | TA-Lib-backed moving averages, momentum, volatility, volume, cycle, and overlap studies | +| Candlestick patterns | Built-in Japanese candlestick pattern recognition | +| OHLCV workflows | Works directly with open, high, low, close, and volume columns | +| Performance | Computation delegated to C routines through `.Call()` | +| Charts | Composable financial charts with optional `{plotly}` and `{ggplot2}` support | @@ -71,13 +70,19 @@ pak::pak("serkor1/ta-lib-R") ## Quick start -All functions provide S3 methods for ``, ``, and---where applicable---`` inputs. The general convention is simple: the output uses the same container type as the input. +All functions provide S3 methods for ``, ``, ``, and---where applicable---`` inputs. The general convention is simple: the output uses the same container type as the input. ```{r quick-start, echo=TRUE} ## calculate the ## relative strength index relative_strength_index <- talib::RSI( - talib::BTC + talib::GOOGL +) + +## check class equivalence +inherits( + relative_strength_index, + class(talib::GOOGL) ) ## display results @@ -93,9 +98,9 @@ original OHLCV rows. ## combine multiple ## indicators features <- cbind( - talib::relative_strength_index(talib::BTC), - talib::bollinger_bands(talib::BTC), - talib::engulfing(talib::BTC) + talib::relative_strength_index(talib::GOOGL), + talib::bollinger_bands(talib::GOOGL), + talib::engulfing(talib::GOOGL) ) tail(features) @@ -107,16 +112,16 @@ tail(features) ```{r charting-example, echo=TRUE} ## subset data and -## store as 'BTC' -BTC <- talib::BTC[1:75, ] +## store as 'GOOGL' +GOOGL <- talib::GOOGL[1:75, ] ## construct chart in a brace block ## alternatively use `|>` { ## initialize main chart talib::chart( - x = BTC, - title = "Bitcoin" + x = GOOGL, + title = "Alphabet Inc." ) ## add Bollinger Bands to diff --git a/man-roxygen/description.R b/man-roxygen/description.R index 06f0babbc..93830e6b0 100644 --- a/man-roxygen/description.R +++ b/man-roxygen/description.R @@ -1,7 +1,8 @@ #' @description #' `<%= tolower(.fun) %>()` is a generic S3 function that preserves #' the input [class]: [data.frame] in, [data.frame] out; [matrix] in, -#' [matrix] out. +#' [matrix] out; `xts` in, `xts` out. Other inputs coercible to +#' [data.frame] (e.g. `zoo`) are computed on the coerced [data.frame]. #' #' <% if (any(grepl(pattern = "cols", x = names(formals(.fun))))) { %> @@ -57,6 +58,10 @@ <% } %> #' #' @param cols ([formula]). An optional `<%= length(all.vars(as.formula(.formula))) %>`-variable [formula] selecting columns from `x` via [model.frame]. +#' For `xts` input each formula variable is matched against the column +#' names directly - exact matches first, then quantmod-style suffix +#' matches (`close` matches `TICKER.Close`), case-insensitively - and +#' columns are consumed in formula order. #' Defaults to `<%= deparse(as.formula(.formula)) %>`. #' <% } %> @@ -82,7 +87,8 @@ #' `NA` values** section above for the consequences. <% } %> <% if ("..." %in% fun_args) { %> -#' @param ... Additional parameters passed into [model.frame]. +#' @param ... Additional parameters passed into [model.frame]. Unused +#' for `xts` input (a warning is emitted when supplied). <% } %> #' #' @author <%= .author %> diff --git a/man-roxygen/rolling_description.R b/man-roxygen/rolling_description.R index 5143c256e..a3fcd1315 100644 --- a/man-roxygen/rolling_description.R +++ b/man-roxygen/rolling_description.R @@ -1,6 +1,7 @@ #' @description #' `<%= tolower(.fun) %>()` is a generic S3 function that preserves -#' the input [class]: [double] vector in, [double] vector out. +#' the input [class]: [double] vector in, [double] vector out; +#' single-column `xts` in, `xts` out. #' #' ## Handling of `NA` values #' @@ -24,9 +25,9 @@ <% if (all(c("x","y") %in% names(formals(.fun)))) { %> -#' @param x,y (([double]), ([double])). A pair of [double] vectors of equal [length]. +#' @param x,y (([double]), ([double])). A pair of [double] vectors of equal [length], or single-column `xts` objects. <% } else { %> -#' @param x ([double]). A [double] vector. +#' @param x ([double]). A [double] vector, or a single-column `xts`. #' <% } %> <% fun_args <- names(formals(.fun)) %> diff --git a/man-roxygen/rolling_returns.R b/man-roxygen/rolling_returns.R index 751b34ec8..c25177306 100644 --- a/man-roxygen/rolling_returns.R +++ b/man-roxygen/rolling_returns.R @@ -1,3 +1,3 @@ #' @returns #' -#' A [double] vector with the same [length] of `x` +#' A [double] vector (or single-column `xts`) with the same [length] of `x` diff --git a/man/examples/indicator.R b/man/examples/indicator.R index 31707f426..8394d4bcd 100644 --- a/man/examples/indicator.R +++ b/man/examples/indicator.R @@ -4,20 +4,20 @@ data(BTC, package = "talib") ## standalone indicator chart ## (no prior chart() call needed) talib::indicator( - talib::RSI, - data = BTC + talib::RSI, + data = BTC ) ## attach an indicator to a price chart talib::chart(BTC) -talib::indicator(talib::RSI, n = 14) +talib::indicator(talib::RSI, timePeriod = 14) ## multiple indicators on the same panel talib::chart(BTC) talib::indicator( - talib::RSI(n = 10), - talib::RSI(n = 14), - talib::RSI(n = 21) + talib::RSI(timePeriod = 10), + talib::RSI(timePeriod = 14), + talib::RSI(timePeriod = 21) ) ## reset chart state diff --git a/man/figures/README-charting-example-1.png b/man/figures/README-charting-example-1.png index 3950d2633..0bb7e048c 100644 Binary files a/man/figures/README-charting-example-1.png and b/man/figures/README-charting-example-1.png differ diff --git a/src/init.c b/src/init.c index 1d5ad3068..f5fccc864 100644 --- a/src/init.c +++ b/src/init.c @@ -85,8 +85,9 @@ static const R_CallMethodDef CallEntries[] = { {"ta_set_compatibility", (DL_FUNC)&ta_set_compatibility, 1}, {"set_candle_setting", (DL_FUNC)&set_candle_setting, 4}, {"reset_candle_setting", (DL_FUNC)&reset_candle_setting, 1}, - {"rownames_data_frame", (DL_FUNC)&rownames_data_frame, 2}, - {"rownames_matrix", (DL_FUNC)&rownames_matrix, 3}, + {"index_data_frame", (DL_FUNC)&index_data_frame, 2}, + {"index_matrix", (DL_FUNC)&index_matrix, 3}, + {"index_xts", (DL_FUNC)&index_xts, 2}, {"map_dfr_double", (DL_FUNC)&map_dfr_double, 1}, {"map_dfr_integer", (DL_FUNC)&map_dfr_integer, 1}, {"initialize_ta_lib", (DL_FUNC)&initialize_ta_lib, 0}, diff --git a/src/names.c b/src/names.c index afea23cdb..c32c21379 100644 --- a/src/names.c +++ b/src/names.c @@ -62,21 +62,21 @@ void set_colnames( // it will crash. // clang-format off -void rownames_data_frame( - SEXP x, +SEXP index_data_frame( + SEXP x, SEXP rownames ) // clang-format on { Rf_setAttrib(x, R_RowNamesSymbol, rownames); - return; + return R_NilValue; } // clang-format off -void rownames_matrix( - SEXP x, - SEXP rownames, +SEXP index_matrix( + SEXP x, + SEXP rownames, SEXP colnames ) // clang-format on @@ -94,5 +94,22 @@ void rownames_matrix( UNPROTECT(1); - return; + return R_NilValue; +} + +// Index of the -object +// +// Installs the 'index'-attribute on x. The value is the +// index of the input -object, i.e. zoo::index(x), +// and is attached as-is. +// clang-format off +SEXP index_xts( + SEXP x, + SEXP index +) +// clang-format on +{ + Rf_setAttrib(x, Rf_install("index"), index); + + return R_NilValue; } \ No newline at end of file diff --git a/src/names.h b/src/names.h index 3c9d04916..cb8d0432e 100644 --- a/src/names.h +++ b/src/names.h @@ -4,7 +4,8 @@ #include void set_colnames(SEXP x, const char *const *names, int k); -void rownames_data_frame(SEXP x, SEXP rownames); -void rownames_matrix(SEXP x, SEXP rownames, SEXP colnames); +SEXP index_data_frame(SEXP x, SEXP rownames); +SEXP index_matrix(SEXP x, SEXP rownames, SEXP colnames); +SEXP index_xts(SEXP x, SEXP index); #endif /* NAMES_H */ diff --git a/src/volume.c b/src/volume.c index 5f4dd1987..8505fe31f 100644 --- a/src/volume.c +++ b/src/volume.c @@ -192,6 +192,14 @@ SEXP impl_ta_VOLUME( set_colnames(out, colname, n_cols); set_attribute(out, LOOKBACK, Rf_ScalarInteger(lookback), &protection_counter); + /* Attach classes to output so its easier to work with downstream */ + SEXP TA_CLASS = PROTECT(Rf_allocVector(STRSXP, 3)); + protection_counter++; + SET_STRING_ELT(TA_CLASS, 0, Rf_mkChar("ta_object")); + SET_STRING_ELT(TA_CLASS, 1, Rf_mkChar("matrix")); + SET_STRING_ELT(TA_CLASS, 2, Rf_mkChar("array")); + Rf_setAttrib(out, R_ClassSymbol, TA_CLASS); + UNPROTECT(protection_counter); return out; } diff --git a/src/wrapper.h b/src/wrapper.h index 8a32a55a2..12b033fa7 100644 --- a/src/wrapper.h +++ b/src/wrapper.h @@ -8,6 +8,7 @@ #define WRAPPER_H #include "NA-handling.h" +#include "Rinternals.h" #include "attributes.h" #include "names.h" #include "normalize.h" @@ -234,6 +235,14 @@ &protection_counter \ ); \ \ + /* Attach classes to output so its easier to work with downstream */ \ + SEXP TA_CLASS = PROTECT(Rf_allocVector(STRSXP, 3)); \ + protection_counter++; \ + SET_STRING_ELT(TA_CLASS, 0, Rf_mkChar("ta_object")); \ + SET_STRING_ELT(TA_CLASS, 1, Rf_mkChar("matrix")); \ + SET_STRING_ELT(TA_CLASS, 2, Rf_mkChar("array")); \ + Rf_setAttrib(out, R_ClassSymbol, TA_CLASS); \ + \ UNPROTECT(protection_counter); \ return out; \ } \ diff --git a/tests/testthat/helper-library.R b/tests/testthat/helper-library.R new file mode 100644 index 000000000..f3d1c9161 --- /dev/null +++ b/tests/testthat/helper-library.R @@ -0,0 +1,3 @@ +if (requireNamespace("xts", quietly = TRUE)) { + library(xts) +} diff --git a/tests/testthat/test-charting.R b/tests/testthat/test-charting.R index b6be91dab..9d498888f 100644 --- a/tests/testthat/test-charting.R +++ b/tests/testthat/test-charting.R @@ -23,8 +23,9 @@ testthat::test_that(desc = "Charting", code = { ## 2) test that indicators ## can be passed with custom - ## data - testthat::expect_no_error( + ## data - a length mismatch against the + ## chart is surfaced as a warning + testthat::expect_warning( { chart(SPY) indicator( @@ -32,7 +33,8 @@ testthat::test_that(desc = "Charting", code = { cols = ~open, data = BTC ) - } + }, + regexp = "differs from the chart" ) }) diff --git a/tests/testthat/test-series.R b/tests/testthat/test-series.R index 37cb1c695..bb115ce94 100644 --- a/tests/testthat/test-series.R +++ b/tests/testthat/test-series.R @@ -1,52 +1,244 @@ ## tests for the formula-based column selector ## series() is internal; we exercise it via the indicator pipeline +testthat::test_that(desc = "Output is ", code = { + ## check + x <- talib:::series( + x = SPY, + formula = ~open, + formula.default = ~open + ) -series <- talib:::series + testthat::expect_s3_class( + x, + "data.frame" + ) -testthat::test_that("series() requires data", { - testthat::expect_error( - series(x = ~close, default_formula = ~close), - "data" + ## check + x <- talib:::series( + x = ATOM, + formula = ~open, + formula.default = ~open + ) + + testthat::expect_s3_class( + x, + "data.frame" ) }) -testthat::test_that("series() falls back to default formula when x is missing", { - df <- data.frame(close = 1:5) - out <- series(default_formula = ~close, data = df) +testthat::test_that(desc = "formula has precedence over formula.default", code = { + ## check ATOM by passing + ## formula explicitly different + ## from the default + x <- talib:::series( + x = ATOM, + formula = ~open, + formula.default = ~close + ) + + ## check that the colnames + ## are are open + testthat::expect_equal( + colnames(x), + "open" + ) - testthat::expect_s3_class(out, "data.frame") - testthat::expect_equal(out$close, 1:5) + ## check that there are no + ## implicit renaming + testthat::expect_equal( + x$open, + ATOM$open + ) }) -testthat::test_that("series() honours explicit formula over default", { - df <- data.frame(close = 1:5, open = 6:10) - out <- series(x = ~open, default_formula = ~close, data = df) +testthat::test_that(desc = "Missing formula does not error", code = { + ## + testthat::expect_no_condition( + talib:::series( + x = ATOM, + formula.default = ~close + ) + ) - testthat::expect_equal(names(out)[1L], "open") + ## + testthat::expect_no_condition( + talib:::series( + x = SPY, + formula.default = ~close + ) + ) }) -testthat::test_that("series() rejects shorter formula than default", { - df <- data.frame(close = 1:5, high = 6:10, low = 11:15) +testthat::test_that(desc = "Attributes are respected", code = { + ## + x <- talib:::series( + x = ATOM, + formula.default = ~ open + high + low + close + volume + ) - ## default expects 3 vars - we pass 1 - testthat::expect_error( - series(x = ~close, default_formula = ~ high + low + close, data = df) + testthat::expect_equal( + x, + ATOM + ) + + ## + x <- talib:::series( + x = SPY, + formula.default = ~ open + high + low + close + volume + ) + + ## NOTE: x is a + ## but SPY are a matrix + testthat::expect_equal( + as.matrix(x), + SPY ) }) -testthat::test_that("series() errors on unknown column", { - df <- data.frame(close = 1:5) +## tests for the column-resolution path: +## columns resolve per formula variable, in formula +## order - never by physical layout +testthat::test_that(desc = " columns resolve in formula order", code = { + testthat::skip_if_not_installed("xts") + + idx <- as.Date("2024-01-01") + 0:9 + ## physical order must not dictate + ## the selection order + x <- xts::xts( + cbind(Low = 0:9, Close = 1:10, High = 2:11), + order.by = idx + ) + + testthat::expect_equal( + colnames(talib:::series(x = x, formula.default = ~ high + low + close)), + c("High", "Low", "Close") + ) + + ## quantmod-style names resolve + ## by suffix + colnames(x) <- paste0("GOOGL.", c("Low", "Close", "High")) + + testthat::expect_equal( + colnames(talib:::series(x = x, formula.default = ~ high + low + close)), + paste0("GOOGL.", c("High", "Low", "Close")) + ) + + ## lowercase names resolve exactly + colnames(x) <- c("low", "close", "high") + + testthat::expect_equal( + colnames(talib:::series(x = x, formula.default = ~ high + low + close)), + c("high", "low", "close") + ) + + ## an explicit formula is selected + ## exactly as passed + testthat::expect_equal( + colnames(talib:::series( + x = x, + formula = ~ low + high + close, + formula.default = ~ high + low + close + )), + c("low", "high", "close") + ) +}) + +testthat::test_that(desc = " column-resolution failures", code = { + testthat::skip_if_not_installed("xts") + + idx <- as.Date("2024-01-01") + 0:9 + x <- xts::xts( + cbind(high = 2:11, low = 0:9, close = 1:10), + order.by = idx + ) + + ## no matching columns + testthat::expect_error( + talib:::series( + x = xts::xts(cbind(a = 1:10, b = 1:10), order.by = idx), + formula.default = ~close + ) + ) + + ## ambiguous matches + ambiguous <- xts::xts(cbind(1:10, 1:10), order.by = idx) + colnames(ambiguous) <- c("Close", "close") + + testthat::expect_error( + talib:::series( + x = ambiguous, + formula.default = ~close + ) + ) + + ## an explicit formula shorter than + ## the default testthat::expect_error( - series(x = ~missing_col, default_formula = ~close, data = df) + talib:::series( + x = x, + formula = ~close, + formula.default = ~ high + low + close + ) + ) + + ## 'subset' and the remaining + ## model.frame-arguments are unused + testthat::expect_warning( + talib:::series( + x = x, + formula.default = ~ high + low + close, + subset = 1:5 + ) ) }) -testthat::test_that("series() coerces non-data.frame to data.frame", { - mat <- matrix(1:10, ncol = 2, dimnames = list(NULL, c("close", "open"))) +## the methods must work without {xts} attached: +## assert_xts() loads the namespace on demand +testthat::test_that(desc = " input works without {xts} attached", code = { + testthat::skip_if_not_installed("xts") + testthat::skip_on_cran() + + script <- paste0( + ".libPaths(", + paste(deparse(.libPaths()), collapse = ""), + "); library(talib); ", + "x <- relative_strength_index(GOOGL); ", + "stopifnot(inherits(x, 'xts'), !all(is.na(x))); ", + "cat('vanilla-ok')" + ) + + output <- suppressWarnings(system2( + file.path(R.home("bin"), "Rscript"), + args = c("--vanilla", "-e", shQuote(script)), + stdout = TRUE, + stderr = TRUE + )) + + testthat::expect_true(any(grepl("vanilla-ok", output))) +}) + +## coercible inputs (zoo, ...) defer to +## as.data.frame() via series.default +testthat::test_that(desc = "coercible inputs defer to as.data.frame()", code = { + testthat::skip_if_not_installed("zoo") + + idx <- as.Date("2024-01-01") + 0:9 + z <- zoo::zoo( + cbind(high = 2:11, low = 0:9, close = 1:10), + order.by = idx + ) + + output <- talib:::series(x = z, formula.default = ~ high + low + close) + + testthat::expect_s3_class(output, "data.frame") + testthat::expect_equal(colnames(output), c("high", "low", "close")) + testthat::expect_equal(rownames(output), as.character(idx)) - testthat::expect_no_error( - out <- series(default_formula = ~close, data = mat) + ## the indicator path computes on the coerced + ## and matches its reference values + testthat::expect_equal( + as.data.frame(relative_strength_index(z)), + relative_strength_index(as.data.frame(z)) ) - testthat::expect_s3_class(out, "data.frame") }) diff --git a/tests/testthat/test-ta_ACCBANDS.R b/tests/testthat/test-ta_ACCBANDS.R index 308ca6dba..10ad1cd57 100644 --- a/tests/testthat/test-ta_ACCBANDS.R +++ b/tests/testthat/test-ta_ACCBANDS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(acceleration_bands(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(acceleration_bands(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(acceleration_bands(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(acceleration_bands(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = accelerationBands_lookback, - expected = acceleration_bands_lookback + object = talib:::accelerationBands_lookback, + expected = talib:::acceleration_bands_lookback ) }) diff --git a/tests/testthat/test-ta_AD.R b/tests/testthat/test-ta_AD.R index 7e213ac2c..bd57acec7 100644 --- a/tests/testthat/test-ta_AD.R +++ b/tests/testthat/test-ta_AD.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(chaikin_accumulation_distribution_line(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(chaikin_accumulation_distribution_line( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_accumulation_distribution_line( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_accumulation_distribution_line(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -174,8 +216,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = chaikinAccumulationDistributionLine_lookback, - expected = chaikin_accumulation_distribution_line_lookback + object = talib:::chaikinAccumulationDistributionLine_lookback, + expected = talib:::chaikin_accumulation_distribution_line_lookback ) }) diff --git a/tests/testthat/test-ta_ADOSC.R b/tests/testthat/test-ta_ADOSC.R index c2695c102..c6cc476ed 100644 --- a/tests/testthat/test-ta_ADOSC.R +++ b/tests/testthat/test-ta_ADOSC.R @@ -53,6 +53,51 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits( + chaikin_accumulation_distribution_oscillator(GOOGL), + class(GOOGL) + ) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(chaikin_accumulation_distribution_oscillator( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_accumulation_distribution_oscillator( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_accumulation_distribution_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -177,8 +222,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = chaikinAccumulationDistributionOscillator_lookback, - expected = chaikin_accumulation_distribution_oscillator_lookback + object = talib:::chaikinAccumulationDistributionOscillator_lookback, + expected = talib:::chaikin_accumulation_distribution_oscillator_lookback ) }) diff --git a/tests/testthat/test-ta_ADX.R b/tests/testthat/test-ta_ADX.R index 7d90debc8..0a7574c59 100644 --- a/tests/testthat/test-ta_ADX.R +++ b/tests/testthat/test-ta_ADX.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(average_directional_movement_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(average_directional_movement_index( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(average_directional_movement_index( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(average_directional_movement_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +213,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = averageDirectionalMovementIndex_lookback, - expected = average_directional_movement_index_lookback + object = talib:::averageDirectionalMovementIndex_lookback, + expected = talib:::average_directional_movement_index_lookback ) }) diff --git a/tests/testthat/test-ta_ADXR.R b/tests/testthat/test-ta_ADXR.R index 56247175a..a9229af28 100644 --- a/tests/testthat/test-ta_ADXR.R +++ b/tests/testthat/test-ta_ADXR.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(average_directional_movement_index_rating(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(average_directional_movement_index_rating( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(average_directional_movement_index_rating( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(average_directional_movement_index_rating(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -177,8 +219,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = averageDirectionalMovementIndexRating_lookback, - expected = average_directional_movement_index_rating_lookback + object = talib:::averageDirectionalMovementIndexRating_lookback, + expected = talib:::average_directional_movement_index_rating_lookback ) }) diff --git a/tests/testthat/test-ta_APO.R b/tests/testthat/test-ta_APO.R index 0afc08570..1c95c14b0 100644 --- a/tests/testthat/test-ta_APO.R +++ b/tests/testthat/test-ta_APO.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(absolute_price_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(absolute_price_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(absolute_price_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(absolute_price_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = absolutePriceOscillator_lookback, - expected = absolute_price_oscillator_lookback + object = talib:::absolutePriceOscillator_lookback, + expected = talib:::absolute_price_oscillator_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_AROON.R b/tests/testthat/test-ta_AROON.R index 74086f794..cfb74d299 100644 --- a/tests/testthat/test-ta_AROON.R +++ b/tests/testthat/test-ta_AROON.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(aroon(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(aroon(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(aroon(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(aroon(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_AROONOSC.R b/tests/testthat/test-ta_AROONOSC.R index 5fe654904..80bfe7370 100644 --- a/tests/testthat/test-ta_AROONOSC.R +++ b/tests/testthat/test-ta_AROONOSC.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(aroon_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(aroon_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(aroon_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(aroon_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = aroonOscillator_lookback, - expected = aroon_oscillator_lookback + object = talib:::aroonOscillator_lookback, + expected = talib:::aroon_oscillator_lookback ) }) diff --git a/tests/testthat/test-ta_ATR.R b/tests/testthat/test-ta_ATR.R index 74cde10ba..b3679a27b 100644 --- a/tests/testthat/test-ta_ATR.R +++ b/tests/testthat/test-ta_ATR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(average_true_range(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(average_true_range(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(average_true_range(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(average_true_range(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = averageTrueRange_lookback, - expected = average_true_range_lookback + object = talib:::averageTrueRange_lookback, + expected = talib:::average_true_range_lookback ) }) diff --git a/tests/testthat/test-ta_AVGDEV.R b/tests/testthat/test-ta_AVGDEV.R index 11e34acaf..a7a7b33bd 100644 --- a/tests/testthat/test-ta_AVGDEV.R +++ b/tests/testthat/test-ta_AVGDEV.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(average_deviation(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(average_deviation(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(average_deviation(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(average_deviation(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = averageDeviation_lookback, - expected = average_deviation_lookback + object = talib:::averageDeviation_lookback, + expected = talib:::average_deviation_lookback ) }) @@ -190,9 +228,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_AVGPRICE.R b/tests/testthat/test-ta_AVGPRICE.R index 3b53ca41c..6649346b2 100644 --- a/tests/testthat/test-ta_AVGPRICE.R +++ b/tests/testthat/test-ta_AVGPRICE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(average_price(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(average_price(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(average_price(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(average_price(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,7 +209,7 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = averagePrice_lookback, - expected = average_price_lookback + object = talib:::averagePrice_lookback, + expected = talib:::average_price_lookback ) }) diff --git a/tests/testthat/test-ta_BBANDS.R b/tests/testthat/test-ta_BBANDS.R index 3e6597f2d..04a8c99b7 100644 --- a/tests/testthat/test-ta_BBANDS.R +++ b/tests/testthat/test-ta_BBANDS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(bollinger_bands(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(bollinger_bands(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(bollinger_bands(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(bollinger_bands(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = bollingerBands_lookback, - expected = bollinger_bands_lookback + object = talib:::bollingerBands_lookback, + expected = talib:::bollinger_bands_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_BETA.R b/tests/testthat/test-ta_BETA.R index fa89c86c5..9408fce70 100644 --- a/tests/testthat/test-ta_BETA.R +++ b/tests/testthat/test-ta_BETA.R @@ -60,3 +60,29 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_beta, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_beta(x = GOOGL[, 1], y = GOOGL[, 2]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_beta( + x = as.numeric(GOOGL[, 1]), + y = as.numeric(GOOGL[, 2]) + )) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_beta(x = GOOGL, y = GOOGL[, 2])) + testthat::expect_error(rolling_beta(x = SPY, y = SPY[, 2])) +}) diff --git a/tests/testthat/test-ta_BOP.R b/tests/testthat/test-ta_BOP.R index 5c403ff07..ea1245015 100644 --- a/tests/testthat/test-ta_BOP.R +++ b/tests/testthat/test-ta_BOP.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(balance_of_power(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(balance_of_power(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(balance_of_power(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(balance_of_power(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = balanceOfPower_lookback, - expected = balance_of_power_lookback + object = talib:::balanceOfPower_lookback, + expected = talib:::balance_of_power_lookback ) }) diff --git a/tests/testthat/test-ta_CCI.R b/tests/testthat/test-ta_CCI.R index 628ad43ab..2bd29db97 100644 --- a/tests/testthat/test-ta_CCI.R +++ b/tests/testthat/test-ta_CCI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(commodity_channel_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(commodity_channel_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(commodity_channel_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(commodity_channel_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = commodityChannelIndex_lookback, - expected = commodity_channel_index_lookback + object = talib:::commodityChannelIndex_lookback, + expected = talib:::commodity_channel_index_lookback ) }) diff --git a/tests/testthat/test-ta_CDL2CROWS.R b/tests/testthat/test-ta_CDL2CROWS.R index 19c2807e4..10ef53790 100644 --- a/tests/testthat/test-ta_CDL2CROWS.R +++ b/tests/testthat/test-ta_CDL2CROWS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(two_crows(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(two_crows(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(two_crows(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(two_crows(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = twoCrows_lookback, - expected = two_crows_lookback + object = talib:::twoCrows_lookback, + expected = talib:::two_crows_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3BLACKCROWS.R b/tests/testthat/test-ta_CDL3BLACKCROWS.R index 80f9fd02b..35cdd01a9 100644 --- a/tests/testthat/test-ta_CDL3BLACKCROWS.R +++ b/tests/testthat/test-ta_CDL3BLACKCROWS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_black_crows(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_black_crows(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_black_crows(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_black_crows(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeBlackCrows_lookback, - expected = three_black_crows_lookback + object = talib:::threeBlackCrows_lookback, + expected = talib:::three_black_crows_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3INSIDE.R b/tests/testthat/test-ta_CDL3INSIDE.R index 8a0467228..ebd9c32ab 100644 --- a/tests/testthat/test-ta_CDL3INSIDE.R +++ b/tests/testthat/test-ta_CDL3INSIDE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_inside(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_inside(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_inside(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_inside(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeInside_lookback, - expected = three_inside_lookback + object = talib:::threeInside_lookback, + expected = talib:::three_inside_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3LINESTRIKE.R b/tests/testthat/test-ta_CDL3LINESTRIKE.R index 47e3e5ecf..8334a6e4c 100644 --- a/tests/testthat/test-ta_CDL3LINESTRIKE.R +++ b/tests/testthat/test-ta_CDL3LINESTRIKE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_line_strike(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_line_strike(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_line_strike(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_line_strike(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeLineStrike_lookback, - expected = three_line_strike_lookback + object = talib:::threeLineStrike_lookback, + expected = talib:::three_line_strike_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3OUTSIDE.R b/tests/testthat/test-ta_CDL3OUTSIDE.R index c475587ca..5aff111ce 100644 --- a/tests/testthat/test-ta_CDL3OUTSIDE.R +++ b/tests/testthat/test-ta_CDL3OUTSIDE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_outside(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_outside(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_outside(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_outside(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeOutside_lookback, - expected = three_outside_lookback + object = talib:::threeOutside_lookback, + expected = talib:::three_outside_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3STARSINSOUTH.R b/tests/testthat/test-ta_CDL3STARSINSOUTH.R index 1ffc00750..e7648ccf3 100644 --- a/tests/testthat/test-ta_CDL3STARSINSOUTH.R +++ b/tests/testthat/test-ta_CDL3STARSINSOUTH.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_stars_in_the_south(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_stars_in_the_south(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_stars_in_the_south(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_stars_in_the_south(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeStarsInTheSouth_lookback, - expected = three_stars_in_the_south_lookback + object = talib:::threeStarsInTheSouth_lookback, + expected = talib:::three_stars_in_the_south_lookback ) }) diff --git a/tests/testthat/test-ta_CDL3WHITESOLDIERS.R b/tests/testthat/test-ta_CDL3WHITESOLDIERS.R index e797561a7..e031dfe1d 100644 --- a/tests/testthat/test-ta_CDL3WHITESOLDIERS.R +++ b/tests/testthat/test-ta_CDL3WHITESOLDIERS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_white_soldiers(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_white_soldiers(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_white_soldiers(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_white_soldiers(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeWhiteSoldiers_lookback, - expected = three_white_soldiers_lookback + object = talib:::threeWhiteSoldiers_lookback, + expected = talib:::three_white_soldiers_lookback ) }) diff --git a/tests/testthat/test-ta_CDLABANDONEDBABY.R b/tests/testthat/test-ta_CDLABANDONEDBABY.R index 45ec30d53..56b9414fe 100644 --- a/tests/testthat/test-ta_CDLABANDONEDBABY.R +++ b/tests/testthat/test-ta_CDLABANDONEDBABY.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(abandoned_baby(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(abandoned_baby(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(abandoned_baby(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(abandoned_baby(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = abandonedBaby_lookback, - expected = abandoned_baby_lookback + object = talib:::abandonedBaby_lookback, + expected = talib:::abandoned_baby_lookback ) }) diff --git a/tests/testthat/test-ta_CDLADVANCEBLOCK.R b/tests/testthat/test-ta_CDLADVANCEBLOCK.R index c227abe68..e1a5e6dde 100644 --- a/tests/testthat/test-ta_CDLADVANCEBLOCK.R +++ b/tests/testthat/test-ta_CDLADVANCEBLOCK.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(advance_block(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(advance_block(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(advance_block(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(advance_block(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = advanceBlock_lookback, - expected = advance_block_lookback + object = talib:::advanceBlock_lookback, + expected = talib:::advance_block_lookback ) }) diff --git a/tests/testthat/test-ta_CDLBELTHOLD.R b/tests/testthat/test-ta_CDLBELTHOLD.R index 900066356..b08bf62a1 100644 --- a/tests/testthat/test-ta_CDLBELTHOLD.R +++ b/tests/testthat/test-ta_CDLBELTHOLD.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(belt_hold(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(belt_hold(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(belt_hold(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(belt_hold(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = beltHold_lookback, - expected = belt_hold_lookback + object = talib:::beltHold_lookback, + expected = talib:::belt_hold_lookback ) }) diff --git a/tests/testthat/test-ta_CDLBREAKAWAY.R b/tests/testthat/test-ta_CDLBREAKAWAY.R index 7929ed752..2f1b20f2f 100644 --- a/tests/testthat/test-ta_CDLBREAKAWAY.R +++ b/tests/testthat/test-ta_CDLBREAKAWAY.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(break_away(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(break_away(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(break_away(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(break_away(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = breakAway_lookback, - expected = break_away_lookback + object = talib:::breakAway_lookback, + expected = talib:::break_away_lookback ) }) diff --git a/tests/testthat/test-ta_CDLCLOSINGMARUBOZU.R b/tests/testthat/test-ta_CDLCLOSINGMARUBOZU.R index 51c46d9cc..017cf11d9 100644 --- a/tests/testthat/test-ta_CDLCLOSINGMARUBOZU.R +++ b/tests/testthat/test-ta_CDLCLOSINGMARUBOZU.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(closing_marubozu(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(closing_marubozu(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(closing_marubozu(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(closing_marubozu(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = closingMarubozu_lookback, - expected = closing_marubozu_lookback + object = talib:::closingMarubozu_lookback, + expected = talib:::closing_marubozu_lookback ) }) diff --git a/tests/testthat/test-ta_CDLCONCEALBABYSWALL.R b/tests/testthat/test-ta_CDLCONCEALBABYSWALL.R index 251b4f2ce..4d9ecaaaf 100644 --- a/tests/testthat/test-ta_CDLCONCEALBABYSWALL.R +++ b/tests/testthat/test-ta_CDLCONCEALBABYSWALL.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(concealing_baby_swallow(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(concealing_baby_swallow(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(concealing_baby_swallow(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(concealing_baby_swallow(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = concealingBabySwallow_lookback, - expected = concealing_baby_swallow_lookback + object = talib:::concealingBabySwallow_lookback, + expected = talib:::concealing_baby_swallow_lookback ) }) diff --git a/tests/testthat/test-ta_CDLCOUNTERATTACK.R b/tests/testthat/test-ta_CDLCOUNTERATTACK.R index fdb6310b0..ff3994d7d 100644 --- a/tests/testthat/test-ta_CDLCOUNTERATTACK.R +++ b/tests/testthat/test-ta_CDLCOUNTERATTACK.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(counter_attack(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(counter_attack(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(counter_attack(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(counter_attack(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = counterAttack_lookback, - expected = counter_attack_lookback + object = talib:::counterAttack_lookback, + expected = talib:::counter_attack_lookback ) }) diff --git a/tests/testthat/test-ta_CDLDARKCLOUDCOVER.R b/tests/testthat/test-ta_CDLDARKCLOUDCOVER.R index d1cc2d240..6844c542a 100644 --- a/tests/testthat/test-ta_CDLDARKCLOUDCOVER.R +++ b/tests/testthat/test-ta_CDLDARKCLOUDCOVER.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(dark_cloud_cover(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(dark_cloud_cover(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(dark_cloud_cover(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(dark_cloud_cover(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = darkCloudCover_lookback, - expected = dark_cloud_cover_lookback + object = talib:::darkCloudCover_lookback, + expected = talib:::dark_cloud_cover_lookback ) }) diff --git a/tests/testthat/test-ta_CDLDOJI.R b/tests/testthat/test-ta_CDLDOJI.R index 3c448493e..3ef3278b7 100644 --- a/tests/testthat/test-ta_CDLDOJI.R +++ b/tests/testthat/test-ta_CDLDOJI.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(doji(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(doji(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(doji(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(doji(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLDOJISTAR.R b/tests/testthat/test-ta_CDLDOJISTAR.R index 7a6f8ec25..f7bb6fb76 100644 --- a/tests/testthat/test-ta_CDLDOJISTAR.R +++ b/tests/testthat/test-ta_CDLDOJISTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(doji_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(doji_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(doji_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(doji_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = dojiStar_lookback, - expected = doji_star_lookback + object = talib:::dojiStar_lookback, + expected = talib:::doji_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLDRAGONFLYDOJI.R b/tests/testthat/test-ta_CDLDRAGONFLYDOJI.R index 4e05f5327..23f6631a7 100644 --- a/tests/testthat/test-ta_CDLDRAGONFLYDOJI.R +++ b/tests/testthat/test-ta_CDLDRAGONFLYDOJI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(dragonfly_doji(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(dragonfly_doji(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(dragonfly_doji(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(dragonfly_doji(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = dragonflyDoji_lookback, - expected = dragonfly_doji_lookback + object = talib:::dragonflyDoji_lookback, + expected = talib:::dragonfly_doji_lookback ) }) diff --git a/tests/testthat/test-ta_CDLENGULFING.R b/tests/testthat/test-ta_CDLENGULFING.R index fe3e34aa7..9aa21a322 100644 --- a/tests/testthat/test-ta_CDLENGULFING.R +++ b/tests/testthat/test-ta_CDLENGULFING.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(engulfing(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(engulfing(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(engulfing(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(engulfing(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLEVENINGDOJISTAR.R b/tests/testthat/test-ta_CDLEVENINGDOJISTAR.R index eb609b7eb..f8068a280 100644 --- a/tests/testthat/test-ta_CDLEVENINGDOJISTAR.R +++ b/tests/testthat/test-ta_CDLEVENINGDOJISTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(evening_doji_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(evening_doji_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(evening_doji_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(evening_doji_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = eveningDojiStar_lookback, - expected = evening_doji_star_lookback + object = talib:::eveningDojiStar_lookback, + expected = talib:::evening_doji_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLEVENINGSTAR.R b/tests/testthat/test-ta_CDLEVENINGSTAR.R index 2ec4d9af4..465f7f2b7 100644 --- a/tests/testthat/test-ta_CDLEVENINGSTAR.R +++ b/tests/testthat/test-ta_CDLEVENINGSTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(evening_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(evening_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(evening_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(evening_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = eveningStar_lookback, - expected = evening_star_lookback + object = talib:::eveningStar_lookback, + expected = talib:::evening_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLGAPSIDESIDEWHITE.R b/tests/testthat/test-ta_CDLGAPSIDESIDEWHITE.R index 0ec6abfa4..94e03e848 100644 --- a/tests/testthat/test-ta_CDLGAPSIDESIDEWHITE.R +++ b/tests/testthat/test-ta_CDLGAPSIDESIDEWHITE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(gaps_side_white(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(gaps_side_white(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(gaps_side_white(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(gaps_side_white(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = gapsSideWhite_lookback, - expected = gaps_side_white_lookback + object = talib:::gapsSideWhite_lookback, + expected = talib:::gaps_side_white_lookback ) }) diff --git a/tests/testthat/test-ta_CDLGRAVESTONEDOJI.R b/tests/testthat/test-ta_CDLGRAVESTONEDOJI.R index d1bc22eb1..a045684f1 100644 --- a/tests/testthat/test-ta_CDLGRAVESTONEDOJI.R +++ b/tests/testthat/test-ta_CDLGRAVESTONEDOJI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(gravestone_doji(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(gravestone_doji(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(gravestone_doji(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(gravestone_doji(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = gravestoneDoji_lookback, - expected = gravestone_doji_lookback + object = talib:::gravestoneDoji_lookback, + expected = talib:::gravestone_doji_lookback ) }) diff --git a/tests/testthat/test-ta_CDLHAMMER.R b/tests/testthat/test-ta_CDLHAMMER.R index 7d9407e32..f446da3b9 100644 --- a/tests/testthat/test-ta_CDLHAMMER.R +++ b/tests/testthat/test-ta_CDLHAMMER.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(hammer(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(hammer(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(hammer(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(hammer(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLHANGINGMAN.R b/tests/testthat/test-ta_CDLHANGINGMAN.R index 6676e75df..dc948e0b6 100644 --- a/tests/testthat/test-ta_CDLHANGINGMAN.R +++ b/tests/testthat/test-ta_CDLHANGINGMAN.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(hanging_man(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(hanging_man(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(hanging_man(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(hanging_man(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = hangingMan_lookback, - expected = hanging_man_lookback + object = talib:::hangingMan_lookback, + expected = talib:::hanging_man_lookback ) }) diff --git a/tests/testthat/test-ta_CDLHARAMI.R b/tests/testthat/test-ta_CDLHARAMI.R index 4180a6b23..378402f97 100644 --- a/tests/testthat/test-ta_CDLHARAMI.R +++ b/tests/testthat/test-ta_CDLHARAMI.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(harami(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(harami(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(harami(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(harami(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLHARAMICROSS.R b/tests/testthat/test-ta_CDLHARAMICROSS.R index 22e33aee8..4cb1d3fbe 100644 --- a/tests/testthat/test-ta_CDLHARAMICROSS.R +++ b/tests/testthat/test-ta_CDLHARAMICROSS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(harami_cross(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(harami_cross(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(harami_cross(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(harami_cross(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = haramiCross_lookback, - expected = harami_cross_lookback + object = talib:::haramiCross_lookback, + expected = talib:::harami_cross_lookback ) }) diff --git a/tests/testthat/test-ta_CDLHIGHWAVE.R b/tests/testthat/test-ta_CDLHIGHWAVE.R index 2db4ab2ac..be80ddfa3 100644 --- a/tests/testthat/test-ta_CDLHIGHWAVE.R +++ b/tests/testthat/test-ta_CDLHIGHWAVE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(high_wave(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(high_wave(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(high_wave(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(high_wave(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = highWave_lookback, - expected = high_wave_lookback + object = talib:::highWave_lookback, + expected = talib:::high_wave_lookback ) }) diff --git a/tests/testthat/test-ta_CDLHIKKAKE.R b/tests/testthat/test-ta_CDLHIKKAKE.R index 4d7547392..2b6da6949 100644 --- a/tests/testthat/test-ta_CDLHIKKAKE.R +++ b/tests/testthat/test-ta_CDLHIKKAKE.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(hikakke(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(hikakke(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(hikakke(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(hikakke(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLHIKKAKEMOD.R b/tests/testthat/test-ta_CDLHIKKAKEMOD.R index 5d598d585..0f9c63630 100644 --- a/tests/testthat/test-ta_CDLHIKKAKEMOD.R +++ b/tests/testthat/test-ta_CDLHIKKAKEMOD.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(hikakke_mod(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(hikakke_mod(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(hikakke_mod(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(hikakke_mod(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = hikakkeMod_lookback, - expected = hikakke_mod_lookback + object = talib:::hikakkeMod_lookback, + expected = talib:::hikakke_mod_lookback ) }) diff --git a/tests/testthat/test-ta_CDLHOMINGPIGEON.R b/tests/testthat/test-ta_CDLHOMINGPIGEON.R index c24bffaf4..ae9771f17 100644 --- a/tests/testthat/test-ta_CDLHOMINGPIGEON.R +++ b/tests/testthat/test-ta_CDLHOMINGPIGEON.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(homing_pigeon(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(homing_pigeon(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(homing_pigeon(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(homing_pigeon(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = homingPigeon_lookback, - expected = homing_pigeon_lookback + object = talib:::homingPigeon_lookback, + expected = talib:::homing_pigeon_lookback ) }) diff --git a/tests/testthat/test-ta_CDLIDENTICAL3CROWS.R b/tests/testthat/test-ta_CDLIDENTICAL3CROWS.R index 7976fe6c9..ce63ddabb 100644 --- a/tests/testthat/test-ta_CDLIDENTICAL3CROWS.R +++ b/tests/testthat/test-ta_CDLIDENTICAL3CROWS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(three_identical_crows(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(three_identical_crows(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(three_identical_crows(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(three_identical_crows(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = threeIdenticalCrows_lookback, - expected = three_identical_crows_lookback + object = talib:::threeIdenticalCrows_lookback, + expected = talib:::three_identical_crows_lookback ) }) diff --git a/tests/testthat/test-ta_CDLINNECK.R b/tests/testthat/test-ta_CDLINNECK.R index 00786c55b..949b315d4 100644 --- a/tests/testthat/test-ta_CDLINNECK.R +++ b/tests/testthat/test-ta_CDLINNECK.R @@ -53,6 +53,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(in_neck(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(in_neck(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(in_neck(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(in_neck(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +207,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = inNeck_lookback, - expected = in_neck_lookback + object = talib:::inNeck_lookback, + expected = talib:::in_neck_lookback ) }) diff --git a/tests/testthat/test-ta_CDLINVERTEDHAMMER.R b/tests/testthat/test-ta_CDLINVERTEDHAMMER.R index 91736f76d..90e371ae5 100644 --- a/tests/testthat/test-ta_CDLINVERTEDHAMMER.R +++ b/tests/testthat/test-ta_CDLINVERTEDHAMMER.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(inverted_hammer(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(inverted_hammer(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(inverted_hammer(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(inverted_hammer(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = invertedHammer_lookback, - expected = inverted_hammer_lookback + object = talib:::invertedHammer_lookback, + expected = talib:::inverted_hammer_lookback ) }) diff --git a/tests/testthat/test-ta_CDLKICKING.R b/tests/testthat/test-ta_CDLKICKING.R index 5a8fd173d..c3e91824f 100644 --- a/tests/testthat/test-ta_CDLKICKING.R +++ b/tests/testthat/test-ta_CDLKICKING.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(kicking(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(kicking(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(kicking(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(kicking(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLKICKINGBYLENGTH.R b/tests/testthat/test-ta_CDLKICKINGBYLENGTH.R index 8f4aa7b4f..f62f245d1 100644 --- a/tests/testthat/test-ta_CDLKICKINGBYLENGTH.R +++ b/tests/testthat/test-ta_CDLKICKINGBYLENGTH.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(kicking_baby_length(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(kicking_baby_length(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(kicking_baby_length(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(kicking_baby_length(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = kickingBabyLength_lookback, - expected = kicking_baby_length_lookback + object = talib:::kickingBabyLength_lookback, + expected = talib:::kicking_baby_length_lookback ) }) diff --git a/tests/testthat/test-ta_CDLLADDERBOTTOM.R b/tests/testthat/test-ta_CDLLADDERBOTTOM.R index 0bc5eddfb..89eb4172a 100644 --- a/tests/testthat/test-ta_CDLLADDERBOTTOM.R +++ b/tests/testthat/test-ta_CDLLADDERBOTTOM.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(ladder_bottom(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(ladder_bottom(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(ladder_bottom(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(ladder_bottom(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = ladderBottom_lookback, - expected = ladder_bottom_lookback + object = talib:::ladderBottom_lookback, + expected = talib:::ladder_bottom_lookback ) }) diff --git a/tests/testthat/test-ta_CDLLONGLEGGEDDOJI.R b/tests/testthat/test-ta_CDLLONGLEGGEDDOJI.R index 0f206eec4..d0386c24e 100644 --- a/tests/testthat/test-ta_CDLLONGLEGGEDDOJI.R +++ b/tests/testthat/test-ta_CDLLONGLEGGEDDOJI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(long_legged_doji(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(long_legged_doji(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(long_legged_doji(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(long_legged_doji(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = longLeggedDoji_lookback, - expected = long_legged_doji_lookback + object = talib:::longLeggedDoji_lookback, + expected = talib:::long_legged_doji_lookback ) }) diff --git a/tests/testthat/test-ta_CDLLONGLINE.R b/tests/testthat/test-ta_CDLLONGLINE.R index 5738cb65e..93ddbd778 100644 --- a/tests/testthat/test-ta_CDLLONGLINE.R +++ b/tests/testthat/test-ta_CDLLONGLINE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(long_line(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(long_line(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(long_line(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(long_line(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = longLine_lookback, - expected = long_line_lookback + object = talib:::longLine_lookback, + expected = talib:::long_line_lookback ) }) diff --git a/tests/testthat/test-ta_CDLMARUBOZU.R b/tests/testthat/test-ta_CDLMARUBOZU.R index 20cc3f005..b5ec8d0fd 100644 --- a/tests/testthat/test-ta_CDLMARUBOZU.R +++ b/tests/testthat/test-ta_CDLMARUBOZU.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(marubozu(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(marubozu(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(marubozu(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(marubozu(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLMATCHINGLOW.R b/tests/testthat/test-ta_CDLMATCHINGLOW.R index 5e48bedc4..da7baadfb 100644 --- a/tests/testthat/test-ta_CDLMATCHINGLOW.R +++ b/tests/testthat/test-ta_CDLMATCHINGLOW.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(matching_low(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(matching_low(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(matching_low(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(matching_low(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = matchingLow_lookback, - expected = matching_low_lookback + object = talib:::matchingLow_lookback, + expected = talib:::matching_low_lookback ) }) diff --git a/tests/testthat/test-ta_CDLMATHOLD.R b/tests/testthat/test-ta_CDLMATHOLD.R index 60ba87730..98b527833 100644 --- a/tests/testthat/test-ta_CDLMATHOLD.R +++ b/tests/testthat/test-ta_CDLMATHOLD.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(mat_hold(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(mat_hold(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(mat_hold(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(mat_hold(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = matHold_lookback, - expected = mat_hold_lookback + object = talib:::matHold_lookback, + expected = talib:::mat_hold_lookback ) }) diff --git a/tests/testthat/test-ta_CDLMORNINGDOJISTAR.R b/tests/testthat/test-ta_CDLMORNINGDOJISTAR.R index 19e9194e8..fbd4aac66 100644 --- a/tests/testthat/test-ta_CDLMORNINGDOJISTAR.R +++ b/tests/testthat/test-ta_CDLMORNINGDOJISTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(morning_doji_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(morning_doji_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(morning_doji_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(morning_doji_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = morningDojiStar_lookback, - expected = morning_doji_star_lookback + object = talib:::morningDojiStar_lookback, + expected = talib:::morning_doji_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLMORNINGSTAR.R b/tests/testthat/test-ta_CDLMORNINGSTAR.R index 6073fe73f..ed659b905 100644 --- a/tests/testthat/test-ta_CDLMORNINGSTAR.R +++ b/tests/testthat/test-ta_CDLMORNINGSTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(morning_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(morning_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(morning_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(morning_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = morningStar_lookback, - expected = morning_star_lookback + object = talib:::morningStar_lookback, + expected = talib:::morning_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLONNECK.R b/tests/testthat/test-ta_CDLONNECK.R index 372497f18..5e70fc40f 100644 --- a/tests/testthat/test-ta_CDLONNECK.R +++ b/tests/testthat/test-ta_CDLONNECK.R @@ -53,6 +53,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(on_neck(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(on_neck(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(on_neck(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(on_neck(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +207,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = onNeck_lookback, - expected = on_neck_lookback + object = talib:::onNeck_lookback, + expected = talib:::on_neck_lookback ) }) diff --git a/tests/testthat/test-ta_CDLPIERCING.R b/tests/testthat/test-ta_CDLPIERCING.R index 035b20694..118b86898 100644 --- a/tests/testthat/test-ta_CDLPIERCING.R +++ b/tests/testthat/test-ta_CDLPIERCING.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(piercing(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(piercing(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(piercing(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(piercing(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLRICKSHAWMAN.R b/tests/testthat/test-ta_CDLRICKSHAWMAN.R index da0fb5026..e58e0885a 100644 --- a/tests/testthat/test-ta_CDLRICKSHAWMAN.R +++ b/tests/testthat/test-ta_CDLRICKSHAWMAN.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(rickshaw_man(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(rickshaw_man(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(rickshaw_man(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(rickshaw_man(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = rickshawMan_lookback, - expected = rickshaw_man_lookback + object = talib:::rickshawMan_lookback, + expected = talib:::rickshaw_man_lookback ) }) diff --git a/tests/testthat/test-ta_CDLRISEFALL3METHODS.R b/tests/testthat/test-ta_CDLRISEFALL3METHODS.R index eb82b9560..95a6be488 100644 --- a/tests/testthat/test-ta_CDLRISEFALL3METHODS.R +++ b/tests/testthat/test-ta_CDLRISEFALL3METHODS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(rise_fall_3_methods(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(rise_fall_3_methods(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(rise_fall_3_methods(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(rise_fall_3_methods(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = riseFall3Methods_lookback, - expected = rise_fall_3_methods_lookback + object = talib:::riseFall3Methods_lookback, + expected = talib:::rise_fall_3_methods_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSEPARATINGLINES.R b/tests/testthat/test-ta_CDLSEPARATINGLINES.R index 98635fc50..d9c0c20ae 100644 --- a/tests/testthat/test-ta_CDLSEPARATINGLINES.R +++ b/tests/testthat/test-ta_CDLSEPARATINGLINES.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(separating_lines(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(separating_lines(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(separating_lines(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(separating_lines(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = separatingLines_lookback, - expected = separating_lines_lookback + object = talib:::separatingLines_lookback, + expected = talib:::separating_lines_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSHOOTINGSTAR.R b/tests/testthat/test-ta_CDLSHOOTINGSTAR.R index 93739a5ac..8ceebe291 100644 --- a/tests/testthat/test-ta_CDLSHOOTINGSTAR.R +++ b/tests/testthat/test-ta_CDLSHOOTINGSTAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(shooting_star(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(shooting_star(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(shooting_star(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(shooting_star(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = shootingStar_lookback, - expected = shooting_star_lookback + object = talib:::shootingStar_lookback, + expected = talib:::shooting_star_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSHORTLINE.R b/tests/testthat/test-ta_CDLSHORTLINE.R index 07f1f8305..cef700ae3 100644 --- a/tests/testthat/test-ta_CDLSHORTLINE.R +++ b/tests/testthat/test-ta_CDLSHORTLINE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(short_line(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(short_line(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(short_line(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(short_line(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = shortLine_lookback, - expected = short_line_lookback + object = talib:::shortLine_lookback, + expected = talib:::short_line_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSPINNINGTOP.R b/tests/testthat/test-ta_CDLSPINNINGTOP.R index 0a32c4408..a71b5ca11 100644 --- a/tests/testthat/test-ta_CDLSPINNINGTOP.R +++ b/tests/testthat/test-ta_CDLSPINNINGTOP.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(spinning_top(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(spinning_top(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(spinning_top(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(spinning_top(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = spinningTop_lookback, - expected = spinning_top_lookback + object = talib:::spinningTop_lookback, + expected = talib:::spinning_top_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSTALLEDPATTERN.R b/tests/testthat/test-ta_CDLSTALLEDPATTERN.R index e5c9c393f..317b0770c 100644 --- a/tests/testthat/test-ta_CDLSTALLEDPATTERN.R +++ b/tests/testthat/test-ta_CDLSTALLEDPATTERN.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(stalled_pattern(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(stalled_pattern(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(stalled_pattern(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(stalled_pattern(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = stalledPattern_lookback, - expected = stalled_pattern_lookback + object = talib:::stalledPattern_lookback, + expected = talib:::stalled_pattern_lookback ) }) diff --git a/tests/testthat/test-ta_CDLSTICKSANDWICH.R b/tests/testthat/test-ta_CDLSTICKSANDWICH.R index afd8436ae..6e7e2a9b1 100644 --- a/tests/testthat/test-ta_CDLSTICKSANDWICH.R +++ b/tests/testthat/test-ta_CDLSTICKSANDWICH.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(stick_sandwich(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(stick_sandwich(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(stick_sandwich(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(stick_sandwich(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = stickSandwich_lookback, - expected = stick_sandwich_lookback + object = talib:::stickSandwich_lookback, + expected = talib:::stick_sandwich_lookback ) }) diff --git a/tests/testthat/test-ta_CDLTAKURI.R b/tests/testthat/test-ta_CDLTAKURI.R index eac53b76d..1a1531ec4 100644 --- a/tests/testthat/test-ta_CDLTAKURI.R +++ b/tests/testthat/test-ta_CDLTAKURI.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(takuri(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(takuri(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(takuri(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(takuri(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLTASUKIGAP.R b/tests/testthat/test-ta_CDLTASUKIGAP.R index a6a9c01c0..5538e6107 100644 --- a/tests/testthat/test-ta_CDLTASUKIGAP.R +++ b/tests/testthat/test-ta_CDLTASUKIGAP.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(tasuki_gap(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(tasuki_gap(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(tasuki_gap(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(tasuki_gap(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = tasukiGap_lookback, - expected = tasuki_gap_lookback + object = talib:::tasukiGap_lookback, + expected = talib:::tasuki_gap_lookback ) }) diff --git a/tests/testthat/test-ta_CDLTHRUSTING.R b/tests/testthat/test-ta_CDLTHRUSTING.R index abf172840..c95344adb 100644 --- a/tests/testthat/test-ta_CDLTHRUSTING.R +++ b/tests/testthat/test-ta_CDLTHRUSTING.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(thrusting(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(thrusting(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(thrusting(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(thrusting(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLTRISTAR.R b/tests/testthat/test-ta_CDLTRISTAR.R index 111ae2979..46fc6b6b9 100644 --- a/tests/testthat/test-ta_CDLTRISTAR.R +++ b/tests/testthat/test-ta_CDLTRISTAR.R @@ -42,6 +42,42 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(tristar(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(tristar(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(tristar(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(tristar(GOOGL[, sort(colnames(GOOGL))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_CDLUNIQUE3RIVER.R b/tests/testthat/test-ta_CDLUNIQUE3RIVER.R index 060e0bdf3..bcc60d889 100644 --- a/tests/testthat/test-ta_CDLUNIQUE3RIVER.R +++ b/tests/testthat/test-ta_CDLUNIQUE3RIVER.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(unique_3_river(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(unique_3_river(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(unique_3_river(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(unique_3_river(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = unique3River_lookback, - expected = unique_3_river_lookback + object = talib:::unique3River_lookback, + expected = talib:::unique_3_river_lookback ) }) diff --git a/tests/testthat/test-ta_CDLUPSIDEGAP2CROWS.R b/tests/testthat/test-ta_CDLUPSIDEGAP2CROWS.R index 3b9064fab..ee4c932d3 100644 --- a/tests/testthat/test-ta_CDLUPSIDEGAP2CROWS.R +++ b/tests/testthat/test-ta_CDLUPSIDEGAP2CROWS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(upside_gap_2_crows(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(upside_gap_2_crows(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(upside_gap_2_crows(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(upside_gap_2_crows(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = upsideGap2Crows_lookback, - expected = upside_gap_2_crows_lookback + object = talib:::upsideGap2Crows_lookback, + expected = talib:::upside_gap_2_crows_lookback ) }) diff --git a/tests/testthat/test-ta_CDLXSIDEGAP3METHODS.R b/tests/testthat/test-ta_CDLXSIDEGAP3METHODS.R index 560702e9d..12444b18b 100644 --- a/tests/testthat/test-ta_CDLXSIDEGAP3METHODS.R +++ b/tests/testthat/test-ta_CDLXSIDEGAP3METHODS.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(xside_gap_3_methods(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(xside_gap_3_methods(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(xside_gap_3_methods(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(xside_gap_3_methods(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = xsideGap3Methods_lookback, - expected = xside_gap_3_methods_lookback + object = talib:::xsideGap3Methods_lookback, + expected = talib:::xside_gap_3_methods_lookback ) }) diff --git a/tests/testthat/test-ta_CMF.R b/tests/testthat/test-ta_CMF.R index d6037c57f..74c2aafe1 100644 --- a/tests/testthat/test-ta_CMF.R +++ b/tests/testthat/test-ta_CMF.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(chaikin_money_flow(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(chaikin_money_flow(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_money_flow(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(chaikin_money_flow(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = chaikinMoneyFlow_lookback, - expected = chaikin_money_flow_lookback + object = talib:::chaikinMoneyFlow_lookback, + expected = talib:::chaikin_money_flow_lookback ) }) diff --git a/tests/testthat/test-ta_CMO.R b/tests/testthat/test-ta_CMO.R index 60309aaf8..b8656718f 100644 --- a/tests/testthat/test-ta_CMO.R +++ b/tests/testthat/test-ta_CMO.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(chande_momentum_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(chande_momentum_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(chande_momentum_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(chande_momentum_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = chandeMomentumOscillator_lookback, - expected = chande_momentum_oscillator_lookback + object = talib:::chandeMomentumOscillator_lookback, + expected = talib:::chande_momentum_oscillator_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_CMOU.R b/tests/testthat/test-ta_CMOU.R index 967ccea0d..d2722bc67 100644 --- a/tests/testthat/test-ta_CMOU.R +++ b/tests/testthat/test-ta_CMOU.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(unsmoothed_chande_momentum_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(unsmoothed_chande_momentum_oscillator( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(unsmoothed_chande_momentum_oscillator( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(unsmoothed_chande_momentum_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -174,8 +216,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = unsmoothedChandeMomentumOscillator_lookback, - expected = unsmoothed_chande_momentum_oscillator_lookback + object = talib:::unsmoothedChandeMomentumOscillator_lookback, + expected = talib:::unsmoothed_chande_momentum_oscillator_lookback ) }) @@ -279,9 +321,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_CORREL.R b/tests/testthat/test-ta_CORREL.R index 1eac60c59..f24354978 100644 --- a/tests/testthat/test-ta_CORREL.R +++ b/tests/testthat/test-ta_CORREL.R @@ -60,3 +60,29 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_correlation, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_correlation(x = GOOGL[, 1], y = GOOGL[, 2]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_correlation( + x = as.numeric(GOOGL[, 1]), + y = as.numeric(GOOGL[, 2]) + )) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_correlation(x = GOOGL, y = GOOGL[, 2])) + testthat::expect_error(rolling_correlation(x = SPY, y = SPY[, 2])) +}) diff --git a/tests/testthat/test-ta_DEMA.R b/tests/testthat/test-ta_DEMA.R index 8fd321bb1..743d6614a 100644 --- a/tests/testthat/test-ta_DEMA.R +++ b/tests/testthat/test-ta_DEMA.R @@ -53,6 +53,46 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(double_exponential_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(double_exponential_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(double_exponential_moving_average( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(double_exponential_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +211,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = doubleExponentialMovingAverage_lookback, - expected = double_exponential_moving_average_lookback + object = talib:::doubleExponentialMovingAverage_lookback, + expected = talib:::double_exponential_moving_average_lookback ) }) @@ -276,9 +316,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_DX.R b/tests/testthat/test-ta_DX.R index 9948141cb..70e599847 100644 --- a/tests/testthat/test-ta_DX.R +++ b/tests/testthat/test-ta_DX.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(directional_movement_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(directional_movement_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(directional_movement_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(directional_movement_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = directionalMovementIndex_lookback, - expected = directional_movement_index_lookback + object = talib:::directionalMovementIndex_lookback, + expected = talib:::directional_movement_index_lookback ) }) diff --git a/tests/testthat/test-ta_EMA.R b/tests/testthat/test-ta_EMA.R index 50f493f8d..32f97db53 100644 --- a/tests/testthat/test-ta_EMA.R +++ b/tests/testthat/test-ta_EMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(exponential_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(exponential_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(exponential_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(exponential_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = exponentialMovingAverage_lookback, - expected = exponential_moving_average_lookback + object = talib:::exponentialMovingAverage_lookback, + expected = talib:::exponential_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HMA.R b/tests/testthat/test-ta_HMA.R index bca9ad22f..d54e10586 100644 --- a/tests/testthat/test-ta_HMA.R +++ b/tests/testthat/test-ta_HMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(hull_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(hull_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(hull_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(hull_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = hullMovingAverage_lookback, - expected = hull_moving_average_lookback + object = talib:::hullMovingAverage_lookback, + expected = talib:::hull_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_DCPERIOD.R b/tests/testthat/test-ta_HT_DCPERIOD.R index 4cd8490f4..f4f1f98c6 100644 --- a/tests/testthat/test-ta_HT_DCPERIOD.R +++ b/tests/testthat/test-ta_HT_DCPERIOD.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(dominant_cycle_period(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(dominant_cycle_period(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(dominant_cycle_period(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(dominant_cycle_period(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = dominantCyclePeriod_lookback, - expected = dominant_cycle_period_lookback + object = talib:::dominantCyclePeriod_lookback, + expected = talib:::dominant_cycle_period_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_DCPHASE.R b/tests/testthat/test-ta_HT_DCPHASE.R index 06680bd3b..fabb65f53 100644 --- a/tests/testthat/test-ta_HT_DCPHASE.R +++ b/tests/testthat/test-ta_HT_DCPHASE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(dominant_cycle_phase(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(dominant_cycle_phase(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(dominant_cycle_phase(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(dominant_cycle_phase(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = dominantCyclePhase_lookback, - expected = dominant_cycle_phase_lookback + object = talib:::dominantCyclePhase_lookback, + expected = talib:::dominant_cycle_phase_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_PHASOR.R b/tests/testthat/test-ta_HT_PHASOR.R index d68729c49..fb24c915b 100644 --- a/tests/testthat/test-ta_HT_PHASOR.R +++ b/tests/testthat/test-ta_HT_PHASOR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(phasor_components(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(phasor_components(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(phasor_components(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(phasor_components(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = phasorComponents_lookback, - expected = phasor_components_lookback + object = talib:::phasorComponents_lookback, + expected = talib:::phasor_components_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_SINE.R b/tests/testthat/test-ta_HT_SINE.R index 9aeb09ada..084576511 100644 --- a/tests/testthat/test-ta_HT_SINE.R +++ b/tests/testthat/test-ta_HT_SINE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(sine_wave(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(sine_wave(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(sine_wave(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(sine_wave(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = sineWave_lookback, - expected = sine_wave_lookback + object = talib:::sineWave_lookback, + expected = talib:::sine_wave_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_TRENDLINE.R b/tests/testthat/test-ta_HT_TRENDLINE.R index 6d6c694e0..0c7fccfb4 100644 --- a/tests/testthat/test-ta_HT_TRENDLINE.R +++ b/tests/testthat/test-ta_HT_TRENDLINE.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(trendline(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(trendline(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(trendline(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(trendline(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -258,9 +296,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_HT_TRENDMODE.R b/tests/testthat/test-ta_HT_TRENDMODE.R index 7606d6f7e..449c2b64d 100644 --- a/tests/testthat/test-ta_HT_TRENDMODE.R +++ b/tests/testthat/test-ta_HT_TRENDMODE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(trend_cycle_mode(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(trend_cycle_mode(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(trend_cycle_mode(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(trend_cycle_mode(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = trendCycleMode_lookback, - expected = trend_cycle_mode_lookback + object = talib:::trendCycleMode_lookback, + expected = talib:::trend_cycle_mode_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_IMI.R b/tests/testthat/test-ta_IMI.R index bc1f760e7..36b3d34b2 100644 --- a/tests/testthat/test-ta_IMI.R +++ b/tests/testthat/test-ta_IMI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(intraday_movement_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(intraday_movement_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(intraday_movement_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(intraday_movement_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = intradayMovementIndex_lookback, - expected = intraday_movement_index_lookback + object = talib:::intradayMovementIndex_lookback, + expected = talib:::intraday_movement_index_lookback ) }) diff --git a/tests/testthat/test-ta_KAMA.R b/tests/testthat/test-ta_KAMA.R index 802cc02b1..b23ac00fd 100644 --- a/tests/testthat/test-ta_KAMA.R +++ b/tests/testthat/test-ta_KAMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(kaufman_adaptive_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(kaufman_adaptive_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(kaufman_adaptive_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(kaufman_adaptive_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = kaufmanAdaptiveMovingAverage_lookback, - expected = kaufman_adaptive_moving_average_lookback + object = talib:::kaufmanAdaptiveMovingAverage_lookback, + expected = talib:::kaufman_adaptive_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MACD.R b/tests/testthat/test-ta_MACD.R index 461f9d724..45258844c 100644 --- a/tests/testthat/test-ta_MACD.R +++ b/tests/testthat/test-ta_MACD.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(moving_average_convergence_divergence(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(moving_average_convergence_divergence( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(moving_average_convergence_divergence( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(moving_average_convergence_divergence(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -174,8 +216,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = movingAverageConvergenceDivergence_lookback, - expected = moving_average_convergence_divergence_lookback + object = talib:::movingAverageConvergenceDivergence_lookback, + expected = talib:::moving_average_convergence_divergence_lookback ) }) @@ -279,9 +321,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MACDEXT.R b/tests/testthat/test-ta_MACDEXT.R index ee5bf6b7c..66462d163 100644 --- a/tests/testthat/test-ta_MACDEXT.R +++ b/tests/testthat/test-ta_MACDEXT.R @@ -59,6 +59,51 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits( + extended_moving_average_convergence_divergence(GOOGL), + class(GOOGL) + ) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(extended_moving_average_convergence_divergence( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(extended_moving_average_convergence_divergence( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(extended_moving_average_convergence_divergence(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -183,8 +228,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = extendedMovingAverageConvergenceDivergence_lookback, - expected = extended_moving_average_convergence_divergence_lookback + object = talib:::extendedMovingAverageConvergenceDivergence_lookback, + expected = talib:::extended_moving_average_convergence_divergence_lookback ) }) @@ -288,9 +333,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MACDFIX.R b/tests/testthat/test-ta_MACDFIX.R index 962c1ff8e..4adfa559f 100644 --- a/tests/testthat/test-ta_MACDFIX.R +++ b/tests/testthat/test-ta_MACDFIX.R @@ -53,6 +53,51 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits( + fixed_moving_average_convergence_divergence(GOOGL), + class(GOOGL) + ) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(fixed_moving_average_convergence_divergence( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(fixed_moving_average_convergence_divergence( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(fixed_moving_average_convergence_divergence(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -177,8 +222,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = fixedMovingAverageConvergenceDivergence_lookback, - expected = fixed_moving_average_convergence_divergence_lookback + object = talib:::fixedMovingAverageConvergenceDivergence_lookback, + expected = talib:::fixed_moving_average_convergence_divergence_lookback ) }) @@ -282,9 +327,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MAMA.R b/tests/testthat/test-ta_MAMA.R index 45b82b846..6d3539a1a 100644 --- a/tests/testthat/test-ta_MAMA.R +++ b/tests/testthat/test-ta_MAMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(mesa_adaptive_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(mesa_adaptive_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(mesa_adaptive_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(mesa_adaptive_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = mesaAdaptiveMovingAverage_lookback, - expected = mesa_adaptive_moving_average_lookback + object = talib:::mesaAdaptiveMovingAverage_lookback, + expected = talib:::mesa_adaptive_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MAVP.R b/tests/testthat/test-ta_MAVP.R index fdea4cadb..4bba3dbc6 100644 --- a/tests/testthat/test-ta_MAVP.R +++ b/tests/testthat/test-ta_MAVP.R @@ -59,6 +59,57 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits( + variable_moving_average_period( + GOOGL, + periods = rep(5, nrow(GOOGL)) + ), + class(GOOGL) + ) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(variable_moving_average_period( + reference, + periods = rep(5, nrow(GOOGL)) + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(variable_moving_average_period( + GOOGL, + periods = rep(5, nrow(GOOGL)) + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(variable_moving_average_period( + GOOGL[, sort(colnames(GOOGL))], + periods = rep(5, nrow(GOOGL)) + ))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -196,8 +247,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = variableMovingAveragePeriod_lookback, - expected = variable_moving_average_period_lookback + object = talib:::variableMovingAveragePeriod_lookback, + expected = talib:::variable_moving_average_period_lookback ) }) @@ -313,9 +364,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MAX.R b/tests/testthat/test-ta_MAX.R index 4e502374c..02fb591c4 100644 --- a/tests/testthat/test-ta_MAX.R +++ b/tests/testthat/test-ta_MAX.R @@ -57,3 +57,26 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_maximum, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_maximum(x = GOOGL[, 1]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_maximum(x = as.numeric(GOOGL[, 1]))) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_maximum(x = GOOGL)) + testthat::expect_error(rolling_maximum(x = SPY)) +}) diff --git a/tests/testthat/test-ta_MEDPRICE.R b/tests/testthat/test-ta_MEDPRICE.R index 3feef755a..2ac9b1158 100644 --- a/tests/testthat/test-ta_MEDPRICE.R +++ b/tests/testthat/test-ta_MEDPRICE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(median_price(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(median_price(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(median_price(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(median_price(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,7 +209,7 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = medianPrice_lookback, - expected = median_price_lookback + object = talib:::medianPrice_lookback, + expected = talib:::median_price_lookback ) }) diff --git a/tests/testthat/test-ta_MFI.R b/tests/testthat/test-ta_MFI.R index 984f257e2..ea0c8ad43 100644 --- a/tests/testthat/test-ta_MFI.R +++ b/tests/testthat/test-ta_MFI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(money_flow_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(money_flow_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(money_flow_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(money_flow_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = moneyFlowIndex_lookback, - expected = money_flow_index_lookback + object = talib:::moneyFlowIndex_lookback, + expected = talib:::money_flow_index_lookback ) }) diff --git a/tests/testthat/test-ta_MIDPOINT.R b/tests/testthat/test-ta_MIDPOINT.R index 2431486bc..339b60a5c 100644 --- a/tests/testthat/test-ta_MIDPOINT.R +++ b/tests/testthat/test-ta_MIDPOINT.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(midpoint_period(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(midpoint_period(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(midpoint_period(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(midpoint_period(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = midpointPeriod_lookback, - expected = midpoint_period_lookback + object = talib:::midpointPeriod_lookback, + expected = talib:::midpoint_period_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_MIDPRICE.R b/tests/testthat/test-ta_MIDPRICE.R index d7427f7b4..32f5e9672 100644 --- a/tests/testthat/test-ta_MIDPRICE.R +++ b/tests/testthat/test-ta_MIDPRICE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(midpoint_price(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(midpoint_price(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(midpoint_price(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(midpoint_price(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = midpointPrice_lookback, - expected = midpoint_price_lookback + object = talib:::midpointPrice_lookback, + expected = talib:::midpoint_price_lookback ) }) diff --git a/tests/testthat/test-ta_MIN.R b/tests/testthat/test-ta_MIN.R index e1f5194fb..2ab68c186 100644 --- a/tests/testthat/test-ta_MIN.R +++ b/tests/testthat/test-ta_MIN.R @@ -57,3 +57,26 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_minimum, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_minimum(x = GOOGL[, 1]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_minimum(x = as.numeric(GOOGL[, 1]))) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_minimum(x = GOOGL)) + testthat::expect_error(rolling_minimum(x = SPY)) +}) diff --git a/tests/testthat/test-ta_MINUS_DI.R b/tests/testthat/test-ta_MINUS_DI.R index 0783afded..f79e3ec44 100644 --- a/tests/testthat/test-ta_MINUS_DI.R +++ b/tests/testthat/test-ta_MINUS_DI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(minus_directional_indicator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(minus_directional_indicator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(minus_directional_indicator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(minus_directional_indicator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = minusDirectionalIndicator_lookback, - expected = minus_directional_indicator_lookback + object = talib:::minusDirectionalIndicator_lookback, + expected = talib:::minus_directional_indicator_lookback ) }) diff --git a/tests/testthat/test-ta_MINUS_DM.R b/tests/testthat/test-ta_MINUS_DM.R index 12057c895..e2e9ed41c 100644 --- a/tests/testthat/test-ta_MINUS_DM.R +++ b/tests/testthat/test-ta_MINUS_DM.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(minus_directional_movement(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(minus_directional_movement(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(minus_directional_movement(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(minus_directional_movement(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = minusDirectionalMovement_lookback, - expected = minus_directional_movement_lookback + object = talib:::minusDirectionalMovement_lookback, + expected = talib:::minus_directional_movement_lookback ) }) diff --git a/tests/testthat/test-ta_MOM.R b/tests/testthat/test-ta_MOM.R index f58f4781e..c59d673be 100644 --- a/tests/testthat/test-ta_MOM.R +++ b/tests/testthat/test-ta_MOM.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(momentum(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(momentum(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(momentum(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(momentum(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -258,9 +296,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_NATR.R b/tests/testthat/test-ta_NATR.R index 7be93951c..8aa50cf7e 100644 --- a/tests/testthat/test-ta_NATR.R +++ b/tests/testthat/test-ta_NATR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(normalized_average_true_range(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(normalized_average_true_range(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(normalized_average_true_range(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(normalized_average_true_range(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = normalizedAverageTrueRange_lookback, - expected = normalized_average_true_range_lookback + object = talib:::normalizedAverageTrueRange_lookback, + expected = talib:::normalized_average_true_range_lookback ) }) diff --git a/tests/testthat/test-ta_NVI.R b/tests/testthat/test-ta_NVI.R index 88e844a63..c40ef30ae 100644 --- a/tests/testthat/test-ta_NVI.R +++ b/tests/testthat/test-ta_NVI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(negative_volume_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(negative_volume_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(negative_volume_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(negative_volume_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = negativeVolumeIndex_lookback, - expected = negative_volume_index_lookback + object = talib:::negativeVolumeIndex_lookback, + expected = talib:::negative_volume_index_lookback ) }) diff --git a/tests/testthat/test-ta_OBV.R b/tests/testthat/test-ta_OBV.R index bb3efc449..cafc8d280 100644 --- a/tests/testthat/test-ta_OBV.R +++ b/tests/testthat/test-ta_OBV.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(on_balance_volume(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(on_balance_volume(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(on_balance_volume(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(on_balance_volume(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = onBalanceVolume_lookback, - expected = on_balance_volume_lookback + object = talib:::onBalanceVolume_lookback, + expected = talib:::on_balance_volume_lookback ) }) diff --git a/tests/testthat/test-ta_PLUS_DI.R b/tests/testthat/test-ta_PLUS_DI.R index fb69803dd..b5e6e25f9 100644 --- a/tests/testthat/test-ta_PLUS_DI.R +++ b/tests/testthat/test-ta_PLUS_DI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(plus_directional_indicator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(plus_directional_indicator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(plus_directional_indicator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(plus_directional_indicator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = plusDirectionalIndicator_lookback, - expected = plus_directional_indicator_lookback + object = talib:::plusDirectionalIndicator_lookback, + expected = talib:::plus_directional_indicator_lookback ) }) diff --git a/tests/testthat/test-ta_PLUS_DM.R b/tests/testthat/test-ta_PLUS_DM.R index 08a95c80f..3f8fe322f 100644 --- a/tests/testthat/test-ta_PLUS_DM.R +++ b/tests/testthat/test-ta_PLUS_DM.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(plus_directional_movement(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(plus_directional_movement(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(plus_directional_movement(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(plus_directional_movement(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = plusDirectionalMovement_lookback, - expected = plus_directional_movement_lookback + object = talib:::plusDirectionalMovement_lookback, + expected = talib:::plus_directional_movement_lookback ) }) diff --git a/tests/testthat/test-ta_PPO.R b/tests/testthat/test-ta_PPO.R index baaaefdb1..50934477d 100644 --- a/tests/testthat/test-ta_PPO.R +++ b/tests/testthat/test-ta_PPO.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(percentage_price_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(percentage_price_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(percentage_price_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(percentage_price_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = percentagePriceOscillator_lookback, - expected = percentage_price_oscillator_lookback + object = talib:::percentagePriceOscillator_lookback, + expected = talib:::percentage_price_oscillator_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_PVI.R b/tests/testthat/test-ta_PVI.R index f0f1946db..6cd99ace8 100644 --- a/tests/testthat/test-ta_PVI.R +++ b/tests/testthat/test-ta_PVI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(positive_volume_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(positive_volume_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(positive_volume_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(positive_volume_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = positiveVolumeIndex_lookback, - expected = positive_volume_index_lookback + object = talib:::positiveVolumeIndex_lookback, + expected = talib:::positive_volume_index_lookback ) }) diff --git a/tests/testthat/test-ta_PVO.R b/tests/testthat/test-ta_PVO.R index e690f585e..15bde42a7 100644 --- a/tests/testthat/test-ta_PVO.R +++ b/tests/testthat/test-ta_PVO.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(percentage_volume_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(percentage_volume_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(percentage_volume_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(percentage_volume_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = percentageVolumeOscillator_lookback, - expected = percentage_volume_oscillator_lookback + object = talib:::percentageVolumeOscillator_lookback, + expected = talib:::percentage_volume_oscillator_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_ROCR.R b/tests/testthat/test-ta_ROCR.R index 158b85d8d..9d1c0c0fb 100644 --- a/tests/testthat/test-ta_ROCR.R +++ b/tests/testthat/test-ta_ROCR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(ratio_of_change(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(ratio_of_change(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(ratio_of_change(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(ratio_of_change(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = ratioOfChange_lookback, - expected = ratio_of_change_lookback + object = talib:::ratioOfChange_lookback, + expected = talib:::ratio_of_change_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_RSI.R b/tests/testthat/test-ta_RSI.R index efedda617..bf405a7f9 100644 --- a/tests/testthat/test-ta_RSI.R +++ b/tests/testthat/test-ta_RSI.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(relative_strength_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(relative_strength_index(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(relative_strength_index(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(relative_strength_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = relativeStrengthIndex_lookback, - expected = relative_strength_index_lookback + object = talib:::relativeStrengthIndex_lookback, + expected = talib:::relative_strength_index_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_SAR.R b/tests/testthat/test-ta_SAR.R index 28cea0b41..0dcf06891 100644 --- a/tests/testthat/test-ta_SAR.R +++ b/tests/testthat/test-ta_SAR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(parabolic_stop_and_reverse(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(parabolic_stop_and_reverse(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(parabolic_stop_and_reverse(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(parabolic_stop_and_reverse(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = parabolicStopAndReverse_lookback, - expected = parabolic_stop_and_reverse_lookback + object = talib:::parabolicStopAndReverse_lookback, + expected = talib:::parabolic_stop_and_reverse_lookback ) }) diff --git a/tests/testthat/test-ta_SAREXT.R b/tests/testthat/test-ta_SAREXT.R index 99fcea294..36ebb88ef 100644 --- a/tests/testthat/test-ta_SAREXT.R +++ b/tests/testthat/test-ta_SAREXT.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(extended_parabolic_stop_and_reverse(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(extended_parabolic_stop_and_reverse( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(extended_parabolic_stop_and_reverse( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(extended_parabolic_stop_and_reverse(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +213,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = extendedParabolicStopAndReverse_lookback, - expected = extended_parabolic_stop_and_reverse_lookback + object = talib:::extendedParabolicStopAndReverse_lookback, + expected = talib:::extended_parabolic_stop_and_reverse_lookback ) }) diff --git a/tests/testthat/test-ta_SMA.R b/tests/testthat/test-ta_SMA.R index 6356c86e4..047fe8d94 100644 --- a/tests/testthat/test-ta_SMA.R +++ b/tests/testthat/test-ta_SMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(simple_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(simple_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(simple_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(simple_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = simpleMovingAverage_lookback, - expected = simple_moving_average_lookback + object = talib:::simpleMovingAverage_lookback, + expected = talib:::simple_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_STDDEV.R b/tests/testthat/test-ta_STDDEV.R index 8b80c8c90..df82e8630 100644 --- a/tests/testthat/test-ta_STDDEV.R +++ b/tests/testthat/test-ta_STDDEV.R @@ -57,3 +57,28 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_standard_deviation, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_standard_deviation(x = GOOGL[, 1]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_standard_deviation( + x = as.numeric(GOOGL[, 1]) + )) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_standard_deviation(x = GOOGL)) + testthat::expect_error(rolling_standard_deviation(x = SPY)) +}) diff --git a/tests/testthat/test-ta_STOCH.R b/tests/testthat/test-ta_STOCH.R index cbc6ef9e7..432531ee7 100644 --- a/tests/testthat/test-ta_STOCH.R +++ b/tests/testthat/test-ta_STOCH.R @@ -42,6 +42,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(stochastic(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(stochastic(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(stochastic(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(stochastic(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_STOCHF.R b/tests/testthat/test-ta_STOCHF.R index dd1fa7d74..188e0f733 100644 --- a/tests/testthat/test-ta_STOCHF.R +++ b/tests/testthat/test-ta_STOCHF.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(fast_stochastic(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(fast_stochastic(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(fast_stochastic(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(fast_stochastic(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = fastStochastic_lookback, - expected = fast_stochastic_lookback + object = talib:::fastStochastic_lookback, + expected = talib:::fast_stochastic_lookback ) }) diff --git a/tests/testthat/test-ta_STOCHRSI.R b/tests/testthat/test-ta_STOCHRSI.R index d06027462..94fb9b6c8 100644 --- a/tests/testthat/test-ta_STOCHRSI.R +++ b/tests/testthat/test-ta_STOCHRSI.R @@ -53,6 +53,48 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(stochastic_relative_strength_index(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(stochastic_relative_strength_index( + reference + ))) + + testthat::expect_equal( + object = unname(zoo::coredata(stochastic_relative_strength_index( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(stochastic_relative_strength_index(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +213,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = stochasticRelativeStrengthIndex_lookback, - expected = stochastic_relative_strength_index_lookback + object = talib:::stochasticRelativeStrengthIndex_lookback, + expected = talib:::stochastic_relative_strength_index_lookback ) }) @@ -276,9 +318,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_SUM.R b/tests/testthat/test-ta_SUM.R index de8da4cd8..5b384f76a 100644 --- a/tests/testthat/test-ta_SUM.R +++ b/tests/testthat/test-ta_SUM.R @@ -57,3 +57,26 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_sum, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_sum(x = GOOGL[, 1]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_sum(x = as.numeric(GOOGL[, 1]))) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_sum(x = GOOGL)) + testthat::expect_error(rolling_sum(x = SPY)) +}) diff --git a/tests/testthat/test-ta_T3.R b/tests/testthat/test-ta_T3.R index a895f4cc2..0fe8d4bbf 100644 --- a/tests/testthat/test-ta_T3.R +++ b/tests/testthat/test-ta_T3.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(t3_exponential_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(t3_exponential_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(t3_exponential_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(t3_exponential_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = t3ExponentialMovingAverage_lookback, - expected = t3_exponential_moving_average_lookback + object = talib:::t3ExponentialMovingAverage_lookback, + expected = talib:::t3_exponential_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_TEMA.R b/tests/testthat/test-ta_TEMA.R index 2673c4212..708ee252f 100644 --- a/tests/testthat/test-ta_TEMA.R +++ b/tests/testthat/test-ta_TEMA.R @@ -53,6 +53,46 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(triple_exponential_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(triple_exponential_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(triple_exponential_moving_average( + GOOGL + ))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(triple_exponential_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +211,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = tripleExponentialMovingAverage_lookback, - expected = triple_exponential_moving_average_lookback + object = talib:::tripleExponentialMovingAverage_lookback, + expected = talib:::triple_exponential_moving_average_lookback ) }) @@ -276,9 +316,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_TRANGE.R b/tests/testthat/test-ta_TRANGE.R index c08da3233..2f668fabb 100644 --- a/tests/testthat/test-ta_TRANGE.R +++ b/tests/testthat/test-ta_TRANGE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(true_range(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(true_range(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(true_range(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(true_range(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = trueRange_lookback, - expected = true_range_lookback + object = talib:::trueRange_lookback, + expected = talib:::true_range_lookback ) }) diff --git a/tests/testthat/test-ta_TRIMA.R b/tests/testthat/test-ta_TRIMA.R index 999d10407..8a10950ee 100644 --- a/tests/testthat/test-ta_TRIMA.R +++ b/tests/testthat/test-ta_TRIMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(triangular_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(triangular_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(triangular_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(triangular_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = triangularMovingAverage_lookback, - expected = triangular_moving_average_lookback + object = talib:::triangularMovingAverage_lookback, + expected = talib:::triangular_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_TRIX.R b/tests/testthat/test-ta_TRIX.R index f4558b8ab..de2b682b4 100644 --- a/tests/testthat/test-ta_TRIX.R +++ b/tests/testthat/test-ta_TRIX.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(triple_exponential_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(triple_exponential_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(triple_exponential_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(triple_exponential_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = tripleExponentialAverage_lookback, - expected = triple_exponential_average_lookback + object = talib:::tripleExponentialAverage_lookback, + expected = talib:::triple_exponential_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } }) diff --git a/tests/testthat/test-ta_TYPPRICE.R b/tests/testthat/test-ta_TYPPRICE.R index 3563eadce..38bcfa5d9 100644 --- a/tests/testthat/test-ta_TYPPRICE.R +++ b/tests/testthat/test-ta_TYPPRICE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(typical_price(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(typical_price(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(typical_price(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(typical_price(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,7 +209,7 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = typicalPrice_lookback, - expected = typical_price_lookback + object = talib:::typicalPrice_lookback, + expected = talib:::typical_price_lookback ) }) diff --git a/tests/testthat/test-ta_ULTOSC.R b/tests/testthat/test-ta_ULTOSC.R index 364a34a53..878517742 100644 --- a/tests/testthat/test-ta_ULTOSC.R +++ b/tests/testthat/test-ta_ULTOSC.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(ultimate_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(ultimate_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(ultimate_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(ultimate_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = ultimateOscillator_lookback, - expected = ultimate_oscillator_lookback + object = talib:::ultimateOscillator_lookback, + expected = talib:::ultimate_oscillator_lookback ) }) diff --git a/tests/testthat/test-ta_VAR.R b/tests/testthat/test-ta_VAR.R index 5bb9ca692..5d35077b8 100644 --- a/tests/testthat/test-ta_VAR.R +++ b/tests/testthat/test-ta_VAR.R @@ -57,3 +57,26 @@ testthat::test_that(desc = 'Lookback equivalence', code = { expected = lookback(FUN = rolling_variance, x = SPY[, 1]) ) }) + +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + output <- rolling_variance(x = GOOGL[, 1]) + + testthat::expect_true(inherits(output, "xts")) + testthat::expect_equal(zoo::index(output), zoo::index(GOOGL)) + testthat::expect_equal( + object = as.numeric(output), + expected = as.numeric(rolling_variance(x = as.numeric(GOOGL[, 1]))) + ) +}) + +## multi-column input must error +## instead of being flattened +testthat::test_that(desc = 'Multivariate input errors', code = { + testthat::skip_if_not_installed("xts") + + testthat::expect_error(rolling_variance(x = GOOGL)) + testthat::expect_error(rolling_variance(x = SPY)) +}) diff --git a/tests/testthat/test-ta_VOLUME.R b/tests/testthat/test-ta_VOLUME.R index 2d5ad295f..9572409fc 100644 --- a/tests/testthat/test-ta_VOLUME.R +++ b/tests/testthat/test-ta_VOLUME.R @@ -42,6 +42,15 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(trading_volume(GOOGL), class(GOOGL)) + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. diff --git a/tests/testthat/test-ta_VWMA.R b/tests/testthat/test-ta_VWMA.R index 06315df74..346b6218a 100644 --- a/tests/testthat/test-ta_VWMA.R +++ b/tests/testthat/test-ta_VWMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(volume_weighted_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(volume_weighted_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(volume_weighted_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(volume_weighted_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = volumeWeightedMovingAverage_lookback, - expected = volume_weighted_moving_average_lookback + object = talib:::volumeWeightedMovingAverage_lookback, + expected = talib:::volume_weighted_moving_average_lookback ) }) diff --git a/tests/testthat/test-ta_WCLPRICE.R b/tests/testthat/test-ta_WCLPRICE.R index 2da136640..a79a88719 100644 --- a/tests/testthat/test-ta_WCLPRICE.R +++ b/tests/testthat/test-ta_WCLPRICE.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(weighted_close_price(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(weighted_close_price(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(weighted_close_price(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(weighted_close_price(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,7 +209,7 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = weightedClosePrice_lookback, - expected = weighted_close_price_lookback + object = talib:::weightedClosePrice_lookback, + expected = talib:::weighted_close_price_lookback ) }) diff --git a/tests/testthat/test-ta_WILLR.R b/tests/testthat/test-ta_WILLR.R index 94c622b69..ef51b5460 100644 --- a/tests/testthat/test-ta_WILLR.R +++ b/tests/testthat/test-ta_WILLR.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(williams_oscillator(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(williams_oscillator(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(williams_oscillator(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(williams_oscillator(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = williamsOscillator_lookback, - expected = williams_oscillator_lookback + object = talib:::williamsOscillator_lookback, + expected = talib:::williams_oscillator_lookback ) }) diff --git a/tests/testthat/test-ta_WMA.R b/tests/testthat/test-ta_WMA.R index 1f04deb4a..0be56fb32 100644 --- a/tests/testthat/test-ta_WMA.R +++ b/tests/testthat/test-ta_WMA.R @@ -53,6 +53,44 @@ testthat::test_that(desc = 'Class in, class out ()', code = { ) }) +## object +testthat::test_that(desc = 'Class in, class out ()', code = { + testthat::skip_if_not_installed("xts") + + ## 1) check that the output class + ## matches the input class + testthat::expect_true( + inherits(weighted_moving_average(GOOGL), class(GOOGL)) + ) +}) + +## the path must select the same columns in the +## same order as the reference, regardless +## of the physical column layout +testthat::test_that(desc = 'Value parity with ()', code = { + testthat::skip_if_not_installed("xts") + + ## lowercase reference + ## from the GOOGL fixture + reference <- as.data.frame(GOOGL) + colnames(reference) <- tolower(sub("^GOOGL\\.", "", colnames(reference))) + reference <- unname(as.matrix(weighted_moving_average(reference))) + + testthat::expect_equal( + object = unname(zoo::coredata(weighted_moving_average(GOOGL))), + expected = reference + ) + + ## alphabetically sorted columns place 'Adjusted' + ## first and must resolve identically + testthat::expect_equal( + object = unname(zoo::coredata(weighted_moving_average(GOOGL[, sort(colnames( + GOOGL + ))]))), + expected = reference + ) +}) + ## check that the default calls ## matches that of the constructed call ## with default values. @@ -171,8 +209,8 @@ testthat::test_that(desc = 'Lookback equivalence', code = { ## the camelCase lookback alias ## is the function itself testthat::expect_identical( - object = weightedMovingAverage_lookback, - expected = weighted_moving_average_lookback + object = talib:::weightedMovingAverage_lookback, + expected = talib:::weighted_moving_average_lookback ) }) @@ -276,9 +314,11 @@ testthat::test_that(desc = ' methods', code = { if (NCOL(x) == 1L) { testthat::expect_true(is.double(x) || is.integer(x)) testthat::expect_false(is.matrix(x)) + testthat::expect_false(inherits(x, "matrix")) testthat::expect_equal(length(x), target_length) } else { testthat::expect_true(is.matrix(x)) + testthat::expect_identical(class(x), c("matrix", "array")) testthat::expect_equal(nrow(x), target_length) } })