Best Loss Function for Shape Resemblance in Time Series Basically, predicting future values step by step using past values and some covariates as a feature, using some LSTM, Conv layers from tensorflow. I started by using mean absolute percentage error as a loss function, but even when it seems fairly low (<10%) it seems the shape tracking could get a lot better. Consider the following curves (not my results, but should give the idea), for example.

It was generated using mape as a loss, and their loss function is higher than mine, but mine does not trace the curve nicely. So was wondering what is the most appropriate loss function for making sure the peaks and valleys in a test set (i.e. future time steps) are tracked by my model? Best if the loss function is differentiable and available in tensorflow readily. Or else, it has to at least follow the standard api of loss functions such as
def (y_true:Iterable[float], y_pred:Iterable[float])->float:
    raise NotImplementedError


There is no "best loss function".
You need to think about what functional of the (unknown) future distribution you want to elicit, then use a loss function that does so. Want the expectation? Use the (R)MSE. Want the median? Use the MAE. Want a quantile? Use a pinball loss. Want the (-1)-median? Use the MAPE. Note that the MAPE may lead to heavily biased forecasts, where "biased" refers to a forecast that is systematically too low compared to the expectation. Which is as it should be, because the MAPE does not aim for an expectation point forecast in the first place, so if you want an expectation forecast, don't use the MAPE. More info can be found in Kolassa (2020).
In the present case, you should first think about whether there is any reason any forecasting system should even in principle be able to anticipate peaks and troughs. The last peak is higher than any peaks before. Do you have predictors that should be helpful at this point in time? If this peak is marked by the exact same Boolean predictor as the peaks before, then you will likely get a forecast that is similar in height to the previous peaks, unless you have seasonality, trend or any other dynamics. See How to know that your machine learning problem is hopeless?
Changing the loss function will not make your algorithm forecast "better" (per above, "better" must be interpreted in the context of the loss function itself!) if the data is not there. The loss function will by itself not provide explanatory information to your algorithm.
