import numpy as np
from converted_code.backshift import backshift

def calculateReturns(prices, lag):
    """
    Python implementation of the MATLAB calculateReturns function.
    Calculates the returns based on the price series over a specified lag.
    
    Parameters:
    prices (ndarray): Array of prices
    lag (int): Lag period for return calculation
    
    Returns:
    ndarray: Calculated returns
    """
    # Get previous prices using backshift
    prevPrices = backshift(lag, prices)
    
    # Calculate returns: (current - previous) / previous
    with np.errstate(divide='ignore', invalid='ignore'):
        rlag = (prices - prevPrices) / prevPrices
    
    return rlag 